取消固定后仍在本地存储中的对象AllInBackground(List<...>,DeleteCallback)



我在Android应用程序中使用Parse.com。我正在制作一个协作购物列表,允许用户标记要删除的项目(它们变成灰色),但只有当我按下同步按钮时,它们才会被实际删除(并且有可用的网络)。目前,对象是从解析数据库中删除的,但不是从本地数据存储中删除的。我正在尝试这个:

 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(),但没有成功。有什么想法吗?

谢谢!

好的,所以我解决了它。根据我的理解,我试图使用解析库做的事情是不可能的。

首先,deleteAllInBackground()还取消固定对象,因此不需要unpinAllInBackground()

问题是,我使用item.pin(MyApplication.ALL_ITEMS)固定对象,因此取消固定对象的唯一方法是使用item.unpinInBackground(MyApplication.ALL_ITEMS)传递固定名称。但是,批处理版本不允许将项集合和管脚名称作为参数传递。因此,不可能使用命名pin批量取消固定项目。

我最终解开了传递pin名称的各个对象。我最大的抱怨是,在没有引脚名称的情况下执行item.unpinInBackground()不会引发异常,因此我不知道问题出在哪里。

最新更新