问题
I'm using Parse.com in my Android app. I'm making a collaborative shopping list which allows the user to mark items for deletion (they turn grey), but they only get actually deleted when I press the Sync button (and there's a network available). Currently, the objects are erased from parse database but not from the local datastore. I'm trying this:
ParseQuery<ShoppingItem> queryDeletes = ShoppingItem.getQuery();
queryDeletes.fromPin(MyApplication.ALL_ITEMS);
queryDeletes.whereEqualTo("isDeleted", true);
queryDeletes.findInBackground(new FindCallback<ShoppingItem>() {
@Override
public void done(final List<ShoppingItem> items, ParseException e) {
if (e == null) {
ShoppingItem.deleteAllInBackground(items, new DeleteCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
ShoppingItem.unpinAllInBackground(items, new DeleteCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
if (!isFinishing()) {
shoppingListAdapter.loadObjects(); // update the list view
}
}
}
});
}
}
});
}
}
});
}
Already tried clearing app data and overriding equals() in ShoppingItem with no success. Any ideas?
Thanks!
回答1:
Ok, so I solved it. From what I understood, what I was trying to do is not possible using the parse library.
First of all, deleteAllInBackground()
also unpins objects, so the unpinAllInBackground()
is not needed.
The problem is that I was pinning the objects using item.pin(MyApplication.ALL_ITEMS)
, thus the only way to unpin them is by passing the pin name using item.unpinInBackground(MyApplication.ALL_ITEMS)
. However, the batch version does not allow to pass as argument both a collection of items AND the pin name. Thus, it isn't possible to batch unpin items with a named pin.
I ended up unpinning the objects individually passing the pin name. The big complain I have is that doing item.unpinInBackground()
without the pin name does not throw an exception and thus I was not aware what the problem was.
来源:https://stackoverflow.com/questions/29264245/objects-still-in-localstore-after-unpinallinbackgroundlist-deletecallback