Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.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
Java 解析:单个saveInBackground调用的重复记录_Java_Android_Parse Platform - Fatal编程技术网

Java 解析:单个saveInBackground调用的重复记录

Java 解析:单个saveInBackground调用的重复记录,java,android,parse-platform,Java,Android,Parse Platform,我有一个事件,数据库中有一个条目的完整副本(同一个用户评论出现了两次)。它们有不同的对象ID,但在其他方面完全相同。它比平时完成发布的速度慢,而且在几十条评论中只发生过一次,所以我想说,在saveInBackground调用期间,这是一个解析问题。即便如此,我还是希望像Parse这样的服务更加健壮。不过,作为我第一次使用安卓系统,我也不能确定我这方面是否出了问题。有什么帮助吗?还有什么批评吗?这是当用户点击评论提交按钮时调用的方法: private void submitComment() {

我有一个事件,数据库中有一个条目的完整副本(同一个用户评论出现了两次)。它们有不同的对象ID,但在其他方面完全相同。它比平时完成发布的速度慢,而且在几十条评论中只发生过一次,所以我想说,在saveInBackground调用期间,这是一个解析问题。即便如此,我还是希望像Parse这样的服务更加健壮。不过,作为我第一次使用安卓系统,我也不能确定我这方面是否出了问题。有什么帮助吗?还有什么批评吗?这是当用户点击评论提交按钮时调用的方法:

private void submitComment() {

    String text = commentText.getText().toString().trim();
    Intent intent = getIntent();
    String ID = intent.getStringExtra("imageID");
    String parentID = intent.getStringExtra("parent");

    // Set up a progress dialog
    final ProgressDialog loadingDialog = new ProgressDialog(CommentSubmitActivity.this);
    loadingDialog.setMessage(getString(R.string.publishing_comment));
    loadingDialog.show();

    Comment comment = new Comment();
    comment.setText(text);
    comment.setUser((ParseUser.getCurrentUser()));
    if (ID.equals("@child")) {
        comment.setParent(parentID);
        comment.setImage("@child");

        ParseQuery<ParseObject> query = ParseQuery.getQuery("Comment");
        query.getInBackground(parentID, new GetCallback<ParseObject>() {
            public void done(ParseObject parentComment, ParseException e) {
                if (e == null) {
                    int numChild = parentComment.getInt("numChild");
                    parentComment.put("numChild", ++numChild);
                    parentComment.saveInBackground();
                } else {
                    Log.d("numChild: ", "error");
                }
            }
        });
    } else {
        comment.setImage(ID);
        comment.put("numChild", 0);

        ParseQuery<ParseObject> query = ParseQuery.getQuery("ImageUpload");
        query.getInBackground(ID, new GetCallback<ParseObject>() {
            public void done(ParseObject image, ParseException e) {
                if (e == null) {
                    int numComments = image.getInt("numComments");
                    image.put("numComments", ++numComments);
                    image.saveInBackground();
                } else {
                    Log.d("numComments: ", "error");
                }
            }
        });

    }

    comment.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                loadingDialog.dismiss();
                finish();
            }
        }
    });
}
private void submitComment(){
字符串文本=commentText.getText().toString().trim();
Intent=getIntent();
字符串ID=intent.getStringExtra(“imageID”);
字符串parentID=intent.getStringExtra(“父”);
//设置进度对话框
final ProgressDialog loadingDialog=新建ProgressDialog(CommentSubmitActivity.this);
loadingDialog.setMessage(getString(R.string.publishing_comment));
加载dialog.show();
注释=新注释();
comment.setText(文本);
comment.setUser((ParseUser.getCurrentUser());
如果(ID.equals(“@child”)){
comment.setParent(parentID);
comment.setImage(“@child”);
ParseQuery=ParseQuery.getQuery(“注释”);
getInBackground(parentID,new GetCallback(){
public void done(ParseObject parentComment,parsee异常){
如果(e==null){
int numChild=parentComment.getInt(“numChild”);
parentComment.put(“numChild”++numChild);
parentComment.savenbackground();
}否则{
Log.d(“numChild:,“error”);
}
}
});
}否则{
注释.setImage(ID);
注释.put(“numChild”,0);
ParseQuery=ParseQuery.getQuery(“ImageUpload”);
getInBackground(ID,newgetcallback(){
公共void完成(ParseObject映像,parsee异常){
如果(e==null){
int numComments=image.getInt(“numComments”);
image.put(“numComments”++numComments);
image.saveInBackground();
}否则{
Log.d(“numComments:,“error”);
}
}
});
}
comment.saveInBackground(新的SaveCallback(){
@凌驾
公共作废完成(Parsee异常){
如果(e==null){
loadingDialog.disclose();
完成();
}
}
});
}

我遇到了与您类似的问题。 我创建了一个应用程序,用户可以在其中创建帐户并向其中添加照片和对象列表(在我的例子中是朋友)。 一次,当我测试它时,用户被创建了两次。 我检查了我的代码,我的怀疑与异步调用有关。 我看到您在应用程序中使用了异步解析api,因此没有代码片段等待响应并阻止其余操作。 您无法控制解析服务器何时响应。 我所做的只是将所有同步请求放入我的自定义异步代码(Android中的AsyncTask)

希望我的回答能满足你的期望