Parse.com saveAllInBackground在deleteAllInBackground中不起作用

时间:2015-06-25 11:43:56

标签: android parse-platform

我正在尝试使用后台全部保存来保存一个parseobjects列表。为避免表中的重复,我正在查询已存在的行并删除它们(如果有)并保存新副本。

执行ParseObject.saveAllInBackground,调用回调,但没有保存任何行。

我确信我传递给saveAllInBackground的列表有parseObjects。

我调试了方法,流程按预期运行。

更新1:

当要删除的行数小于添加的行数时,较新的行将保持不变。意思是,传递给deleteallinbackground方法的列表中不存在的行会保持不变。

这是我的代码

       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();
                                            }
                                        });
                                    }
                                }
                            });


                        }
                    }
                });

1 个答案:

答案 0 :(得分:0)

  • query.fromPin(); - 这可能是您使用的本地数据存储区,不确定
  • ParseObject.saveAllInBackground(localList...确保localList不为空。当你调用save方法时,我怀疑它是什么。
  • 前两个查询会自行公布,只需进行此查询而不是那两个:

    ParseQuery query = new ParseQuery("PostChoice");
    query.whereEqualTo("user",ParseUser.getCurrentUser());
    
  • 我不确定,但嵌套bacground回调可能有限制。您可能会尝试从其中一个回调中调用活动类中的方法,这将继续链。