Android - Cloud Save不起作用

时间:2013-12-29 14:50:28

标签: java android google-app-engine byte google-cloud-storage

我在我的应用中实施了Cloud Save。该示例工作正常(使用我的包和密钥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);

在我的设备中,我收到始终为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;
          ....

1 个答案:

答案 0 :(得分:2)

kl1是插槽ID,而不是已保存的数据。我们将使用保存的数据值调用您的onStateLoadedonStateConflict方法。