【发布时间】:2013-12-29 14:50:28
【问题描述】:
我已经在我的应用中实现了云保存。该示例工作正常(使用我的包和密钥 SHA,与控制台相同)。所以,我用这个修改了示例代码。我有两个按钮
上传:save to cloud
void saveToCloud() {
//public int cLUN1 = 3; kl1 is the int stateKey (slot) ; bLUN1 the byte
byte[] bLUN1 = String.valueOf(cLUN1).getBytes();
getAppStateClient().updateStateImmediate(this, kl1, bLUN1);
下载:download from cloud
void saveToDevice() {
//mint1 is the textview ; kl1 the slot to restore
getAppStateClient().loadState(this, kl1);
mint1.setText(" "+kl1);
从我的设备我收到 always 0 作为 TextView mint1 的文本。为什么我没有得到正确的变量?
编辑:解决方案
void saveToCloud() {
bLUN1 = String.valueOf(cLUN1).getBytes();
bLUN2 = String.valueOf(cLUN2).getBytes();
getAppStateClient().updateStateImmediate(this, key1, bLUN1);
getAppStateClient().updateStateImmediate(this, key2, bLUN2);
}
void loadFromCloud() {
mLoadingDialog.show();
getAppStateClient().loadState(this, key1);
getAppStateClient().loadState(this, key2);
}
我还编辑了onStateLoaded
@Override
public void onStateLoaded(int statusCode, int stateKey, byte[] localData) {
mLoadingDialog.dismiss();
switch (statusCode) {
case AppStateClient.STATUS_OK:
mAlreadyLoadedState = true;
hideAlertBar();
mint1.setText(new String(bLUN1, charset));
mint2.setText(new String(bLUN2, charset));
break;
....
【问题讨论】:
标签: java android google-app-engine byte google-cloud-storage