问题描述
我在Android应用中使用Parse.com.我正在制作一个协作式购物清单,该清单允许用户标记要删除的项目(它们变成灰色),但是只有在我按同步"按钮(并且有可用的网络)时,它们才会被实际删除.当前,将从解析数据库中删除对象,但不会从本地数据存储中删除对象.我正在尝试:
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
}
}
}
});
}
}
});
}
}
});
}
已经尝试清除ShoppingItem中的应用程序数据并覆盖equals(),但未成功.有什么想法吗?
Already tried clearing app data and overriding equals() in ShoppingItem with no success. Any ideas?
谢谢!
推荐答案
好,所以我解决了.据我了解,我尝试使用解析库是不可能的.
Ok, so I solved it. From what I understood, what I was trying to do is not possible using the parse library.
首先,deleteAllInBackground()
还会取消固定对象,因此不需要unpinAllInBackground()
.
First of all, deleteAllInBackground()
also unpins objects, so the unpinAllInBackground()
is not needed.
问题是我使用item.pin(MyApplication.ALL_ITEMS)
固定了对象,因此取消固定的唯一方法是使用item.unpinInBackground(MyApplication.ALL_ITEMS)
传递了引脚名称.但是,批处理版本不允许将项目的集合和引脚名称作为参数传递.因此,无法使用命名的固定销批量取消固定固定销.
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.
我最终取消了分别通过引脚名称来固定对象的操作.我最大的抱怨是在没有引脚名的情况下执行item.unpinInBackground()
不会引发异常,因此我不知道问题出在哪里.
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.
这篇关于unpinAllInBackground(List< ...> ;, DeleteCallback)之后,对象仍在localstore中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!