的parseObject pinInBackground返回null OBJECTID [英] ParseObject pinInBackground returning null objectId

查看:244
本文介绍了的parseObject pinInBackground返回null OBJECTID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在本地数据存储创建一个的parseObject ,并将其存储在Android项目code块。然而,当我去查OBJECTID在()完成 的回调方法pinInBackground()则返回null。如果我从 pinInBackground()切换到 saveInBackground()然后正常工作和有效的ObjectId中给出。这里是code:

I have a block of code in an Android project that creates a ParseObject and stores it in the local datastore. However, when I go to check the objectId in the done() callback method of pinInBackground() it returns null. If I switch from pinInBackground() to saveInBackground() then it works fine and a valid objectId is given. Here is the code:

final ParseObject testObject = new ParseObject("TestObject");

testObject.put("foo", "bar2");
testObject.pinInBackground(new SaveCallback() {
  @Override
  public void done(ParseException e) {
      if (e != null) {
          Log.e(TAG, "Failed to pin TestObject: " + e.getMessage());
          return;
      }

      Log.d(TAG, "Added key-value pair to TestObject '" + testObject.getObjectId() + "': 'foo' => 'bar2'");
  }

});

日志显示:

添加键值对到的TestObject'空':'富'=> BAR2

为什么是空OBJECTID?我是否需要设置它,因为它不保存到云?

Why is the objectId null? Do I need to set it since it's not saving to the cloud?

推荐答案

的问题是,你是不是保存对象到数据库的解析,只到设备,所以对象实际上并没有尚未创建。 pinInBackground()只储存到设备中,而saveInBackground()被保存到数据库的解析,从而实际创建的对象。如果你使用.saveEventually(),将针,直到网络可以到达保存到数据库的解析。但在一般 - 你不会实际上只保存到您的设备创建一个对象,它必须被保存到数据库解析创建。

The problem is that you are not saving object to the Parse database, only to the device, so the object has not actually been created yet. pinInBackground() is only saving to the device, while saveInBackground() is saving to the Parse database, thereby, actually creating the object. If you use .saveEventually(), that will pin until the network can be reached to save to the Parse database. But in general - you will not actually create an object by only saving to your device, it must be saved to the Parse database to create.

这篇关于的parseObject pinInBackground返回null OBJECTID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆