将本地存储的parseobject保存到云端

时间:2015-04-20 07:07:46

标签: android parse-platform

我正在尝试使用以下代码保存一些数据来解析云:

 ParseObject po=new ParseObject("Gamescore");
  po.put("score",myscore);
  po.saveInBackground();

我成功保存此对象以解析云。但我需要先将其存储在本地,然后在用户单击按钮时,解析对象必须更新Parse Cloud中的表并将其自我保存在云端。请不要将代码视为任何游戏场景,这只是一个例子,我正在使用。 我试图理解parse.com文档,但它没那么有用。

1 个答案:

答案 0 :(得分:0)

使用本地数据存储https://parse.com/docs/android_guide#localdatastore

您可以执行以下操作:

ParseObject po=new ParseObject("Gamescore");
po.put("score",myscore);
po.pinInBackground(); // now it is saved locally

然后用户按下按钮

ParseQuery<ParseObject> query = ParseQuery.get("Gamescore")
.fromLocalDatastore()
.findInBackground(new FindCallback() {
    public void done(List<ParseObject> objects, ParseException e) {
      // all Gamescores pinned locally
      for (ParseObject score: objects) {
          // keep in local database till successfully saved online
          score.saveEventually();
      }
}
});

除了saveEventually(),您当然也可以简单地执行saveAllInBackground(),如果您有许多对象,这会更有效率,但如果没有互联网连接,它会在某个时刻超时。