James
James

Reputation: 557

getting ParseUser object

Hi I am using the Parse API's database for users and I was wondering how to get the actual ParseUser object so that I can add fields to it? Would I have to query to get the id first then retrieve the obejct that way? As in

ParseQuery query = new ParseQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
    } else {
      // something went wrong
    }
  }
});

Is there an easier way...

Upvotes: 3

Views: 2566

Answers (1)

hank
hank

Reputation: 3768

Do you mean the currently logged in user?

ParseUser currentUser = ParseUser.getCurrentUser();

Of do you have a relation to a user in another class? If that is the case you can use ParseQuery.include to include that class in the response also.

ParseQuery query = new ParseQuery("GameScore");
query.include("User");
query.getInBackground("xWMyZ4YEGZ", new GetCallback() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
      ParseUser user = object.getParseObject("User"); // We have a user object
    } else {
      // something went wrong
    }
  }
});

Be aware for typos made here :)

Upvotes: 2

Related Questions