My requirement is to differentiate between first time and subsequent Google-sign in in my android application. For first time user google sign-in, I want to redirect the user to the profile screen, where he will fill additional information regarding his contact details. After his first google sign in, all the subsequent google sign-in, I want the user to be directed directly to the home screen, without filling out the Profile details once again. I use Firebase for my backend. I have followed a couple of stack overflow questions and providing the link for the same below.
Link 1: Correct code location to check Firebase if a user has been created already?
I was able to achieve my requirement with a simple bug, which I couldn't figure out what I am missing. First time Google sign-in directs to Profile screen and subsequent requests redirects to Home screen. But what I tried, it happens only until the user closes the app. If the user closes the application and opens again, the user is redirected to the profile screen, which shouldn't happen. Once the user signs in with Google and has registered with the Profile, all the subsequent requests should go to Home screen.
My Bug: When the user closes the app and reopens again, the user is redirected to the Profile screen on google sign in. Here is what I have tried
SignInActivity.java
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SignInActivity.this);
if (firebaseAuth.getCurrentUser() != null) {
if (!sharedPreferences.contains(String.valueOf(Preferences.FIRST_LAUNCH))) {
Intent contactDetailsIntent = new Intent(SignInActivity.this, ContactDetailsActivity.class);
startActivity(contactDetailsIntent);
sharedPreferences.edit().putBoolean(String.valueOf(Preferences.FIRST_LAUNCH), true).commit();
} else {
Intent loginIntent = new Intent(SignInActivity.this,MainMenuActivity.class);
startActivity(loginIntent);
finish();
}
}
Here is my preferences class.
public class Preferences {
public static final boolean FIRST_LAUNCH = false;
public static final String NAME = "fullName";
public static final String EMAIL = "email";
public static final String USERID = "userId";
public static final String USER_TYPE = "userType";
}
I am unable to figure out what the issue is. Any help is appreciated