Parse-SDK-Android
Parse-SDK-Android copied to clipboard
ParseUser.getCurrentUser() sometimes returning null
I am experiencing some strange behaviour in my android app. Some weeks ago I activated the Google Analytics Crash Report on my app, and sometimes I can see a NullPointerException been raised just in the statement ParseUser.getCurrentUser().getString(...). The activity where this happens is only accessed after the user has been logged in. I don't know why this happens. I know about a closed issue #179 reporting the same problem, but I decided to open a new one. I tried reproduce the problem in many different situations, but I can't reproduced the error.
That is a bug in Parse core. Very difficult to reproduce it.
We have the same problem. The workaround we are using now is saving the username and password in SharedPreference, and when ParseUser.getCurrentUser()
returns null, we log the user in manually:
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
ParseUser.logIn(sp.getString("username", null), sp.getString("password", null));
@iForests I highly recommend against doing this as it compromises the user's credentials by storing it in plaintext.
@grantland Oh, there're only anonymous users in our app, so I think it's okay in this situation.
@iForests I still don't recommend it as it compromises the user's account.
I can reproduce this issue. We have extended ParseUser class to add our custom data and many times when we try to resume the home activity, we can see this crash coming in. ClassCastException.
@keyur47831 Did you find a fix ?
I did experienced the same issue. It turns out that my problem was that I was pinning objects without waiting for the callback. ie : I was pinning several ParseObjects consecutively without waiting for the pin operation to complete. Seems to be a problem for Parse... Since after that the LocalDataStore was corrupted and the CurrentParseUser was null.
Hope that'll help