AVInstallation save有bug (Android sdk)

使用如下代码维护_Installation表中的三个字段,主要是跟_User表中的user做对应。

public static void refreshInstallation(final User user) {
        Log.d("PushHelper", "refreshInstallation, user is null: " + (user == null));
        AVInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
            @Override
            public void done(AVException e) {
                if (e != null) {
                    e.printStackTrace();
                }
                final AVInstallation currentInstallation = AVInstallation.getCurrentInstallation();
                Log.d("PushHelper", "first save");
                Log.d("PushHelper", currentInstallation.toJSONObject().toString());
                if (user == null) {
                    currentInstallation.put(INSTALLATION_USER_NAME, "");
                    currentInstallation.put(INSTALLATION_USER_TYPE, "");
                    currentInstallation.put(INSTALLATION_TOWN_INFO, "");
                } else {
                    Log.d("PushHelper", "user: " + user.getUsername() + ", type: " + user.getUserType()
                            + ", town: " + user.getWorkerTownInfo());
                    currentInstallation.put(INSTALLATION_USER_NAME, user.getUsername());
                    currentInstallation.put(INSTALLATION_USER_TYPE, user.getUserType());
                    currentInstallation.put(INSTALLATION_TOWN_INFO, user.getWorkerTownInfo() == null ? "" : user.getWorkerTownInfo());
                }
                Log.d("PushHelper", "local data: " + currentInstallation.toJSONObject().toString());
                currentInstallation.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(AVException e) {
                        Log.d("PushHelper", "second save");
                        Log.d("PushHelper", AVInstallation.getCurrentInstallation().toJSONObject().toString());
                    }
                });
            }
        });
    }

当应用内退出登陆后,看到log内没有问题,本地的_Installation 的缓存内相对应的字段已经清空,但是后台_Installation表中这3个字段还是上一个用户的值。

05-31 00:06:30.964  10958-10958/com.xichexia.android D/PushHelper﹕ refreshInstallation, user is null: false
05-31 00:06:31.107  10958-10958/com.xichexia.android D/PushHelper﹕ first save
05-31 00:06:31.107  10958-10958/com.xichexia.android D/PushHelper﹕ {"deviceType":"android","installationTownInfo":"","installationUserType":"","installationUserName":"","installationId":"c4f61a87-8846-49c4-9046-43889e875de7","updatedAt":"2015-05-30T16:06:31.736Z","createdAt":"2015-05-30T15:11:19.081Z","objectId":"5569d317e4b09f185ebac82b","timeZone":"Asia\/Shanghai"}
05-31 00:06:31.108  10958-10958/com.xichexia.android D/PushHelper﹕ user: 13162928601, type: user, town:
05-31 00:06:31.108  10958-10958/com.xichexia.android D/PushHelper﹕ local data: {"deviceType":"android","installationTownInfo":"","installationUserType":"user","installationUserName":"13162928601","installationId":"c4f61a87-8846-49c4-9046-43889e875de7","updatedAt":"2015-05-30T16:06:31.736Z","createdAt":"2015-05-30T15:11:19.081Z","objectId":"5569d317e4b09f185ebac82b","timeZone":"Asia\/Shanghai"}
05-31 00:06:31.180  10958-10958/com.xichexia.android D/PushHelper﹕ second save
05-31 00:06:31.180  10958-10958/com.xichexia.android D/PushHelper﹕ {"deviceType":"android","installationTownInfo":"","installationUserType":"user","installationUserName":"13162928601","installationId":"c4f61a87-8846-49c4-9046-43889e875de7","updatedAt":"2015-05-30T16:06:31.859Z","createdAt":"2015-05-30T15:11:19.081Z","objectId":"5569d317e4b09f185ebac82b","timeZone":"Asia\/Shanghai"}

然后再在应用内用另一个用户登陆,同样的,看log没问题,字段已更新,变成了新用户所对应的值,但是后台_Installation表中的三个字段,变成空了。后台_Installation表字段的更新永远『滞后』一次。如果不是bug,该怎么更新这个表,或者说,怎么手动维护_Installation和_User表的关系?

我不是很明白你为什么要写两次saveInBackground。你完全可以通过更新数据,然后一次保存完成这个功能新工作啊

已经解决了,还是要用两次saveInBackground才能保存数据。

public static void refreshInstallation(final User user) {
        Log.d("PushHelper", "refreshInstallation, user is null: " + (user == null));
        final AVInstallation currentInstallation = AVInstallation.getCurrentInstallation();
        if (user == null) {
            currentInstallation.put(INSTALLATION_USER_NAME, "");
            currentInstallation.put(INSTALLATION_USER_TYPE, "");
            currentInstallation.put(INSTALLATION_TOWN_INFO, "");
        } else {
            currentInstallation.put(INSTALLATION_USER_NAME, user.getUsername());
            currentInstallation.put(INSTALLATION_USER_TYPE, user.getUserType());
            currentInstallation.put(INSTALLATION_TOWN_INFO, user.getWorkerTownInfo() == null ? "" : user.getWorkerTownInfo());
        }
        currentInstallation.saveInBackground(new SaveCallback() {
            @Override
            public void done(AVException e) {
                currentInstallation.saveInBackground();
            }
        });
    }

如代码所示,一定要save两次才能确保后台被保存,否则只有本地的数据被更新,后台还是老数据。

现在还是这样么???我看到一个崩溃啊

AVInstallation这个里面的调用堆栈中字典有问题,已经崩了800+了