使用如下代码维护_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表的关系?
-
创建时间
15年5月31日
-
最后回复
16年5月3日
- 3
回复
- 1.4K
浏览
- 3
用户