-2

I have added bottom navigation bar and the home fragment is set as the main page of the app but the code which checks if the user is logged in or not is not working, every time, if I log out the app, should start from login but it starts from the home fragment.

Firebase mAuth = FirebaseAuth.getInstance();

@Override
protected void onStart() {
    super.onStart();

        FirebaseUser currentUser = mAuth.getCurrentUser();

        if (currentUser == null){
            sendStart();
        }
    }

I have added this code but still, if the user is null it opens the main page and every time I restart the app it opens the main page of activity

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
ATUL YADAV
  • 1
  • 1
  • 5

2 Answers2

1

As per you - when you log out the app, should start from login but it starts from the home fragment.

I am not sure but Means, it may be possible user not logged out properly.So, you need to signout properly.

Show below to Signout :-

firebaseAuth.signOut();
Auth.GoogleSignInApi.signOut(apiClient);

Then check, user is logged in or not using:-

FirebaseAuth.getInstance().getCurrentUser();

If it return null means user is not logged in.

Janvi Vyas
  • 732
  • 5
  • 16
0

On log out you have to log out like that :

firebaseAuth.signOut();
Auth.GoogleSignInApi.signOut(apiClient);

You check whether user logged in or not using this :

FirebaseAuth.getInstance().getCurrentUser()

For more information Please take a look here

moosa0709
  • 476
  • 3
  • 12