简体   繁体   中英

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?

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 thisnasty 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM