Android pass firebase auth object to another activity to logout
I am logged in to login to the main activity, but I want to log out to another activity with a button. However, I am unable to pass the object to FirebaseAuth
another activity.
PutParcelable and PutSerializable won't work because I can't control the class itself. General preference only accepts primitive types. Should I get a new instance in a new activity and log out of the user account in a new activity? Does user state persist even if I get a new instance?
here is the code
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
Toast.makeText(getApplicationContext(), "You are logged in!!!",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this, CameraActivity.class);
startActivity(intent);
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
+3
source to share