Reputation: 283
I am having a Parse Starter Application on Android Studio (downloaded from the github of Parse) and I am using Heroku yo have Parse Server.
I can add collections with no problem but with the users I am having difficulties...
[JavaCode]
if(ParseUser.getCurrentUser() == null){
ParseAnonymousUtils.logIn(new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
if (e != null) {
Log.i("MyApp", "Anonymous login failed.");
} else {
Log.i("MyApp", "Anonymous user logged in.");
}
}
});
}
else{
//Log.i("MyApp", ParseUser.getCurrentUser().getUsername());
Log.i("MyApp", "User already logged in");
}
and in my StarterApplication file I have:
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
When running, my debugger prints 'user already logged in' but if I uncomment the above line, application crashes. On the Parse dashboard, there's no 'User' class and of course no User Objects.
I have tried deploying app in a completely new emulator with no other apps installed and I still have the same problem!!! any ideas???
Upvotes: 0
Views: 744
Reputation: 885
This code is correct as is - you are simply misunderstanding how the anonymous user works in Parse. When you put
ParseUser.enableAutomaticUser();
in your MyApplication class (which I assume is what you meant by your "StarterApplication" file), you have told Parse that you want to allow users to access your database anonymously (aka without logging in). Once you tell Parse that, Parse.getCurrentUser() will ALWAYS return a user. Straight out of Parse's documentation:
When you enable automatic anonymous user creation at application startup, ParseUser.getCurrentUser() will never be null.
So since you used ParseUser.enableAutomaticUser(), once you call Parse.getCurrentUser(), it never returns null, therefore you are seeing the printout "User already logged in." Admittedly, that user is essentially blank, but they are a user nonetheless.
Read the section in this guide on Anonymous Users for more information: https://parse.com/docs/android/guide
Upvotes: 1