ParseObject pinInBackground returns null objectId

I have a block of code in an android project that creates ParseObject

and stores it in local data storage. However, when I go to check the objectId in the callback method done()

pinInBackground()

, it returns null. If I switch from pinInBackground()

to saveInBackground()

then it works fine and a valid objectId is set. 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'");
  }

      

});

The log displays:

Added key-value pair to TestObject 'null': 'foo' => 'bar2'

Why is objectId null? Do I need to install it since it is not stored in the cloud?

+3


source to share


1 answer


The problem is that you are not storing the object in the device-only Parse database, so the object has not been created yet. pinInBackground () only saves to the device, while saveInBackground () saves the Parse database, thus actually creating the object. If you use .saveEventually () this will be displayed until the network is available to save in the Parse database. But in general - you will not actually create an object, only by saving it to your device, it must be saved to the analysis database for creation.



+6


source







All Articles