【问题标题】:Android - Cloud Save doesn't workAndroid - 云保存不起作用
【发布时间】: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


    【解决方案1】:

    kl1 是 slot id,而不是保存的数据。将使用保存的数据值调用您的 onStateLoadedonStateConflict 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 2011-07-26
      • 1970-01-01
      • 2016-09-14
      • 1970-01-01
      • 2015-12-10
      • 2018-12-16
      相关资源
      最近更新 更多