Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SaveAllInBackground不';t根据需要在deleteAllInBackground内工作_Android_Parse Platform - Fatal编程技术网

Android SaveAllInBackground不';t根据需要在deleteAllInBackground内工作

Android SaveAllInBackground不';t根据需要在deleteAllInBackground内工作,android,parse-platform,Android,Parse Platform,SaveAllInBackground在deleteAllInBackground中无法按需要工作 我正在尝试使用save all in background保存ParseObject的列表。为了避免表中出现重复,我正在查询已经存在的行并删除它们(如果有的话),然后保存新的副本。因此,我在deleteAllInBackground的回调中调用saveAllInBackground 问题是: 例如:如果要删除的列表包含[a,b,c,d],并且要上载的列表只有[a,b,c,d,e,f]需要解析。我正

SaveAllInBackground在deleteAllInBackground中无法按需要工作

我正在尝试使用save all in background保存ParseObject的列表。为了避免表中出现重复,我正在查询已经存在的行并删除它们(如果有的话),然后保存新的副本。因此,我在deleteAllInBackground的回调中调用saveAllInBackground

问题是:

例如:如果要删除的列表包含[a,b,c,d],并且要上载的列表只有[a,b,c,d,e,f]需要解析。我正在将[a,b,c,d,e,f]传递到saveAllInBackground,但只有[e,f]被持久化

  • 我有什么遗漏吗?如何解决这个问题

  • 我可以使用不同的方法吗

  • 有没有更好的方法避免重复?我不想再加一句 在保存钩子之前。调用saveAll的全部目的是减少API调用的数量。我想如果我使用beforeSave,我将不得不在云代码中运行一些查询

这是我的密码

            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() {
                                        @Override
                                        public void done(ParseException e) {
                                            Log.i("SyncChoiceService", "Synced Choices");
                                            editor.putLong(Four.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis());
                                            editor.commit();
                                        }
                                    });
                                }
                            }
                        });


                    }
                }
            });
ParseQuery query=newparsequery(“后选择”);
query.fromPin();
findInBackground(新的FindCallback(){
@凌驾
公共作废完成(最终列表localList,parsee){
if(localList!=null&&!localList.isEmpty()){
List postList=new ArrayList();
用于(ParseObject对象:localList){
add(object.getParseObject(“post”);
}
ParseQuery查询=新的ParseQuery(“后选择”);
查询。其中包含在(“post”,postList);
query.whereEqualTo(“user”,ParseUser.getCurrentUser());
findInBackground(新的FindCallback(){
@凌驾
public void done(List parseCloudList,parsee异常){
if(parseCloudList!=null&&!parseCloudList.isEmpty()){
deleteAllInBackground(parseCloudList,新的DeleteCallback()){
@凌驾
公共作废完成(Parsee异常){
//将执行此操作并相应地删除行
saveAllInBackground(localList,new SaveCallback()){
@凌驾
公共作废完成(Parsee异常){
//将执行此操作,但不会上载行。
//locallist不是空的。它包含正确的数据。
editor.putLong(4.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis());
commit();
Log.i(“同步选择服务”、“同步选择”);
}
});
}
});
}
否则{
saveAllInBackground(localList,new SaveCallback()){
@凌驾
公共作废完成(Parsee异常){
Log.i(“同步选择服务”、“同步选择”);
editor.putLong(4.LAST\u CHOICE\u SYNC\u TIME,System.currentTimeMillis());
commit();
}
});
}
}
});
}
}
});

是的,如果我理解正确,您只想将localdb中的新数据保存到parse backend

最好的、请求较少的解决方案是在表中有另一个名为“Draft”或“isUpdated”(根据需要命名)的字段。此标志的作用是标识此字段是否保存在后端。如果新字段“IsUpdate”为false,则为true。然后在查询中,您只能查询isUpdated为false的数据。然后将它们保存在后端。然后

  • 您不想删除任何数据
  • 减少请求
  • 减少代码中不必要的逻辑
  • 干净

  • 希望这有帮助

    我想出了这样的解决方案。它符合我的要求。我使用updatedValue并删除旧的,其余的作为一个完整的列表更新

    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.whereLessThan("updatedAt",System.currentTimeMillis());
                            query.whereEqualTo("user", ParseUser.getCurrentUser());
                            query.findInBackground(new FindCallback<ParseObject>() {
                                @Override
                                public void done(final List<ParseObject> parseCloudList, ParseException e) {
                                    if (parseCloudList != null && !parseCloudList.isEmpty()) {
                                        ParseObject.deleteAllInBackground(parseCloudList, new DeleteCallback() {
                                            @Override
                                            public void done(ParseException e) {
                                                Log.i("SyncChoiceService", "Deleted old  Choices");
    
                                            }
                                        });
                                    }
    
    
                                        }
                                    });
    
    
    ParseObject.saveAllInBackground(localList, new SaveCallback() {
            @Override
            public void done(ParseException e) {
                Log.i("SyncChoiceService", "Synced Choices");
            }
        });
    
                        }
                    }
                });
    
    ParseQuery query=newparsequery(“后选择”);
    query.fromPin();
    findInBackground(新的FindCallback(){
    @凌驾
    公共作废完成(最终列表localList,parsee){
    if(localList!=null&&!localList.isEmpty()){
    List postList=new ArrayList();
    用于(ParseObject对象:localList){
    add(object.getParseObject(“post”);
    }
    ParseQuery查询=新的ParseQuery(“后选择”);
    查询。其中包含在(“post”,postList);
    query.whereLessThan(“updatedAt”,System.currentTimeMillis());
    query.whereEqualTo(“user”,ParseUser.getCurrentUser());
    findInBackground(新的FindCallback(){
    @凌驾
    公共作废完成(最终列表parseCloudList,ParseException e){
    如果(解析)