How to Update data in parse server platform in android?

Viewed 109

I am trying to updating the data in parse server platform, but couldn't save the data. It does not showing any error log or error message.

Here is my following code for saving


public void OnSubmit(View view) {


        ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
       // ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("User"); //tried this, not working
       // query.whereEqualTo("username",ParseUser.getCurrentUser().getUsername()); //tried this but not working
        query.getInBackground("ZoMFWRvm4k", new GetCallback<ParseObject>() {
            @Override
            public void done(ParseObject object, ParseException e) {
                if (e == null){
                    object.put("name",editText.getText().toString());
                    object.saveInBackground(new SaveCallback() {
                        @Override
                        public void done(ParseException e) {
                            if (e == null){
                                Toast.makeText(EditPage.this, "Your Name saved successfully", Toast.LENGTH_SHORT).show();
                                Intent intent = new Intent(EditPage.this, ProfilePageActivity.class);
                                startActivity(intent);
                                //finish();
                            }else {
                                Toast.makeText(EditPage.this, "Oops... There is an error, please try again", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            }
        });
}


1 Answers

With the help of ParseQuery<ParseObject> it should work, but in your case it doesn't that's strange. As you mentioned in the question you didn't get any error logs so I think your button click does not give any instruction.

Even I face this problem so I use like this try to use in different way. Here is the code:-


 ParseUser user = ParseUser.getCurrentUser();

 user.put("name",editText.getText().toString()); // we can put other for example email, birth place like this for updating

                user.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e==null){
                            Toast.makeText(EditPage.this, "Your Name saved successfully", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(EditPage.this, ProfilePageActivity.class);
                            startActivity(intent);
                            finish();
                        }else {
                            Toast.makeText(EditPage.this, "Ops!! error", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
}

ParseUser user = ParseUser.getCurrentUser(); 

by the help of above line of code you can get your current login user.

Related