Android更新用户有parse.com

时间:2015-09-30 03:33:10

标签: android parse-platform android-parser

我有用户得分5.我想要用得分为6的用户更新。你能帮助我。

ParseUser user = ParseUser.getCurrentUser();
        if (user == null){
            return;
        }
        if (userName.equals(user.getUsername())) {
            user.put(PlayerModel.PARSE_FIELD_SCORE_PLAYER,
                     6);
            user.signUpInBackground(new SignUpCallback() {
                @Override
                public void done(final ParseException e) {
                    if (e != null) {
                        Log.e(">>>>>PlayerProvider",e.getMessage());
                    }
                }
            });
        }

我改变相同的代码后,但没有成功。你能帮帮我吗?

  user.saveInBackground(new SaveCallback() {
                    public void done(com.parse.ParseException e) {
                        // TODO Auto-generated method stub
                        if (e != null) {
                            Log.e(">>>>>PlayerProvider",e.getMessage());
                        } else {

                        }
                    }
                });

记录错误

09-30 10:23:13.512  19848-19848/com.demo.b E/>>>>>PlayerProvider﹕ username vbox86pvbox86p16Samsung Galaxy S3 - 4.1.1 - API 16 - 720x1280000000000000000310260000000000 already taken

1 个答案:

答案 0 :(得分:0)

您可以使用incremen

文档:https://parse.com/docs/android/guide#objects-counters

前:

ParseUser user = ParseUser.getCurrentUser();
user.incremen(PlayerModel.PARSE_FIELD_SCORE_PLAYER);
user.saveInBackground();

编辑:

ParseUser user = ParseUser.getCurrentUser();
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.getInBackground(user.getObjectId(), new GetCallback<ParseUser>() {
    @Override
    public void done(ParseUser parseUser, ParseException e) {
        if (e == null) {
            parseUser.put(PlayerModel.PARSE_FIELD_SCORE_PLAYER, 9999);
            parseUser.saveInBackground();
        }
    }
});