3

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...

1 Answer 1

2

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 :)

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the answer I understand what you mean! I was also looking at the currentUser but I was just curious how it works. Is it just defined as the last logged in user that did not log out? Wouldnt this not work if multiple users try to log in?
The currently logged in user on the app, on the device. Can't be more than one, right?
There can only be one user logged in at any time. currentUser will be null if you log out.
oo ok that makes sense i thought that it was cached on the database... will the user stay logged in even if the application closes?
Yes, the user will stay logged in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.