Objects still in localstore after unpinAllInBackground(List<…>, DeleteCallback)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 11:25:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!