Change user with Firebase Google user authentication java code example
Example 1: firebase auth get current user
var user = firebase.auth().currentUser;var name, email, photoUrl, uid, emailVerified;if (user != null) { name = user.displayName; email = user.email; photoUrl = user.photoURL; emailVerified = user.emailVerified; uid = user.uid; // The user's ID, unique to the Firebase project. Do NOT use // this value to authenticate with your backend server, if // you have one. Use User.getToken() instead.}
Example 2: how to check if user is logged in firebase android and then load another activity
private FirebaseAuth firebaseAuth;
FirebaseAuth.AuthStateListener mAuthListener;
firebaseAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener(){
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth){
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
};