parse-platformparse-android-sdk

Parse Andorid SDK: remove label from a local pin


I'm using Parse SDK's localDataStore to implement offline-capable Android app.

When users create new objects, they're pinned locally with a special label. When it's time to sync offline changes to the server, I search for all objects pinned with that label and save them. At that point, after the object is synced to the server, I want to remove the label, but keep the object pinned locally. The only way I found to achieve that is this:

parseObject.save();
parseObject.unpin(ParsePinLabels.MODIFIED_OFFLINE);
parseObject.pin();

Two problems with this approach:

  1. Takes too long
  2. Ugly

My intuition says that in this scenario it should be enough to just remove the label from the already pinned ParseObject, but I can't find a way to do that without full unpin. What do I miss?


Solution

  • Eventually, I couldn't find a way to just remove the label from a pinned object, without unpinning it.

    So, we either need to pin the object after unpinning:

    parseObject.save();
    parseObject.unpin(ParsePinLabels.MODIFIED_OFFLINE);
    parseObject.pin();
    

    Or, as suggested by Davi in the comments, we could pin the object with two different labels to begin with, and then just keep one of them forever:

    // when pinning
    parseObject.pin(ParsePinLabels.DUMMY_LABEL);
    parseObject.pin(ParsePinLabels.MODIFIED_OFFLINE);
    
    // when syncing to the server
    parseObject.save();
    parseObject.unpin(ParsePinLabels.MODIFIED_OFFLINE); // object remains pinned with dummy label
    

    However, when using the second approach, you might run into this nasty unresolved bug when using ParseObject.unpinAll(). Therefore, if you use the second approach, you'll need to remember to unpin all objects in this manner:

    ParseObject.unpinAll()
    ParseObject.unpinAll(ParsePinLabels.DUMMY_LABEL)