I need to authenticate user with firebase (Google or Facebook). Then i want user to add some more deatils about him in NewUserActivity, and then enter the main core of the app. For checking if its first time launch i use
prefManager.isFirstTimeLaunch
This works ok with no problem But i have a bug. If user uninstall and reinstall the app, as normal its like he is launching the app first time. So i need to check if he already has an account. I use
FirebaseUserMetadata metadata = mAuth.getCurrentUser().getMetadata();
if (metadata.getCreationTimestamp() == metadata.getLastSignInTimestamp())
So this its suppose to check if the user is not new one (had already an account).
My full checking code is:
mAuthListner = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null) {
FirebaseUserMetadata metadata = mAuth.getCurrentUser().getMetadata();
if (metadata.getCreationTimestamp() == metadata.getLastSignInTimestamp()) {
if (prefManager.isFirstTimeLaunch()) {
startActivity(new Intent(MainActivity.this, NewUserActivity.class));
}
}
else
{
startActivity(new Intent(MainActivity.this, UserProfile.class));
finishAffinity();
}
}
}
};
THE PROBLEM:
The code goes ALLWAYS in UserProfile Activity. So even if the user is new, doesnt go to NewUserActivity to add the details, and as the UserProfile Activity havent the details needed, throws null exception.
As i can understand the problem is that this code
if (metadata.getCreationTimestamp() == metadata.getLastSignInTimestamp())
is not working. Without this line app works fine EXCEPT if user uninstall and reinstall the app. In this case its like a new user.
Generally speaking is a very normal scenario of authenticate user in firebase, add some details in an activity for first time, and then always be in profile.
I had this part of code for long time with no problem. The strange behavior started a week before with no actually reason. So i m almost convinced its firebase problem.
Clarification
No need for logcat as the null exception has to do that code ALWAYS go to UserProfile so hasnt got the details needed.