I am checking if the current user is logged into my app and has never once signed out. If it is true, and upon launching my app, it will open Activity A/B, depending on the value of userDepartment
stored in database.
My codes are like this:
firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = firebaseAuth.getCurrentUser();
//user has logged in and never once logged out. auto bring to the specific dashboard page based on account type.
if (user != null) {
finish();
final String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("userDepartment").child(uid);
if (databaseReference.equals("Administrator")) {
startActivity(new Intent(MainActivity.this, SecondActivity.class));
} else {
startActivity(new Intent(MainActivity.this, LocalUserDashboard.class));
}
}
The logic is not working as when I signed in as Administrator, close the app but DID NOT sign out, the expected outcome is the Administrator user will be brought to SecondActivity
class. However, it opened up the LocalUserDashboard
class instead. Then, if I login as Local User, close the app and did not sign out, it does bring me to the LocalUserDashboard
class, just as intended.
I am not entirely sure if my codes are right as I did it while depending on various sources both in SO as well as the official documents and kinda just mixing everything up.
Please help me. Thank you.
Below is my database structure: