Parse.com saveAllInBackground内deleteAllInBackground不起作用 [英] Parse.com saveAllInBackground doesn't work inside deleteAllInBackground

查看:157
本文介绍了Parse.com saveAllInBackground内deleteAllInBackground不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存使用保存所有背景parseobjects的列表。为了避免在表duplices,我查询了已有的行,而且如果任何删除它们并保存新的副本。

该ParseObject.saveAllInBackground被execued,回调越来越调用,但没有行得到保存。

我相信我传递给saveAllInBackground列表中有parseObjects。

我调试的方法,如预期的流动运行。

更新1:

当要删除的行的数量小于加到行数,较新的行得到持续。这意味着,不在传递给deleteallinbackground方法列表present得到持久的行

这是我的code

  ParseQuery查询=新ParseQuery(PostChoice);                query.fromPin();
                query.findInBackground(新FindCallback<&的parseObject GT;(){
                    @覆盖
                    公共无效完成(最终名单<&的parseObject GT; localList,ParseException的E){
                        如果(localList =空&放大器;!&放大器;!localList.isEmpty()){
                            清单<&的parseObject GT; postList =新的ArrayList<&的parseObject GT;();
                            对于(的parseObject对象:localList){                                postList.add(object.getParseObject(后));
                            }
                            ParseQuery查询=新ParseQuery(PostChoice);
                            query.whereContainedIn(后,postList);
                            query.whereEqualTo(用户,ParseUser.getCurrentUser());
                            query.findInBackground(新FindCallback<&的parseObject GT;(){
                                @覆盖
                                公共无效完成(列表<&的parseObject GT; parseCloudList,ParseException的E){                                    如果(parseCloudList =空&放大器;!&放大器;!parseCloudList.isEmpty()){
                                        ParseObject.deleteAllInBackground(parseCloudList,新DeleteCallback(){
                                            @覆盖
                                            公共无效完成(ParseException的E){
                   //这会被执行并且行也将被删除
                                                ParseObject.saveAllInBackground(localList,新SaveCallback(){
                                                    @覆盖
                                                    公共无效完成(ParseException的E){
    //这个被执行,但行没有上传。
    //将locallist不是空的。它包含正确的数据。
                                                        editor.putLong(Four.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis的());
                                                        editor.commit();
                                                        Log.i(SyncChoiceService,同步的选择);
                                                    }
                                                });
                                            }
                                        });
                                    }
                                    其他{
                                        ParseObject.saveAllInBackground(localList,新SaveCallback(){//此方法效果很好,上传。该问题仅出现在saveAllInBackground被称为deleteAllInBackground的电话里回                                            @覆盖
                                            公共无效完成(ParseException的E){
                                                Log.i(SyncChoiceService,同步的选择);
                                                editor.putLong(Four.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis的());
                                                editor.commit();
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                });


解决方案

  • query.fromPin(); - 这可能是使用本地数据存储,不知道

  • ParseObject.saveAllInBackground(localList ... 确保localList不是空的。我怀疑它是当你调用保存方法。

  • 首先两个查询dublicate自己,才使这个查询,而不是这两个:

      ParseQuery查询=新ParseQuery(PostChoice);
    query.whereEqualTo(用户,ParseUser.getCurrentUser());


  • 林不知道,但有可能是嵌套bacground回调的极限。你可能会尝试从回调的一个调用的方法在你的活动类,即继续链。

I am trying to save a list of parseobjects using save all in background. To avoid duplices in the table, I am querying for the already existing rows and deleting them if any and save the new copy.

The ParseObject.saveAllInBackground gets execued, the callbacks are getting called, but no rows are getting saved.

I am sure the list I am passing to the saveAllInBackground has parseObjects.

I debugged the methods, the flow runs as intended.

Update 1:

When the number of rows to delete is less than the number of rows added, the newer rows get persisted. Meaning, the rows that are not present in the list passed to deleteallinbackground method get persisted.

This is my code

       ParseQuery query = new ParseQuery("PostChoice");

                query.fromPin();
                query.findInBackground(new FindCallback<ParseObject>() {
                    @Override
                    public void done(final List<ParseObject> localList, ParseException e) {
                        if (localList != null && !localList.isEmpty()) {
                            List<ParseObject> postList = new ArrayList<ParseObject>();
                            for (ParseObject object : localList) {

                                postList.add(object.getParseObject("post"));
                            }
                            ParseQuery query = new ParseQuery("PostChoice");
                            query.whereContainedIn("post", postList);
                            query.whereEqualTo("user", ParseUser.getCurrentUser());
                            query.findInBackground(new FindCallback<ParseObject>() {
                                @Override
                                public void done(List<ParseObject> parseCloudList, ParseException e) {

                                    if (parseCloudList != null && !parseCloudList.isEmpty()) {
                                        ParseObject.deleteAllInBackground(parseCloudList, new DeleteCallback() {
                                            @Override
                                            public void done(ParseException e) {
                   // this gets executed and rows are accordingly deleted                             
                                                ParseObject.saveAllInBackground(localList, new SaveCallback() {
                                                    @Override
                                                    public void done(ParseException e) {
    // this gets executed but the rows are not uploaded. 
    //the locallist is not empty. it contains the right data.
                                                        editor.putLong(Four.LAST_CHOICE_SYNC_TIME, System.currentTimeMillis());
                                                        editor.commit();
                                                        Log.i("SyncChoiceService", "Synced Choices");
                                                    }
                                                });
                                            }
                                        });
                                    }
                                    else{
                                        ParseObject.saveAllInBackground(localList, new SaveCallback() {

//This method works fine and uploads. The issue arises only when saveAllInBackground is called inside deleteAllInBackground's call back

                                            @Override
                                            public void done(ParseException e) {
                                                Log.i("SyncChoiceService", "Synced Choices");
                                                editor.putLong(Four.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis());
                                                editor.commit();
                                            }
                                        });
                                    }
                                }
                            });


                        }
                    }
                });

解决方案

  • query.fromPin(); - this might be using your local datastore, not sure
  • ParseObject.saveAllInBackground(localList... make sure that localList is not empty. I have a suspicion it is when you call the save method.
  • First two queries dublicate themselves, just make this query instead of those two:

    ParseQuery query = new ParseQuery("PostChoice");
    query.whereEqualTo("user",ParseUser.getCurrentUser());
    

  • im not sure, but there might be a limit to nesting bacground callbacks. You might try to call a method in your activity class from one of the callbacks, that continues the chain.

这篇关于Parse.com saveAllInBackground内deleteAllInBackground不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆