0

This is my coding in my java class file where my log out button is located at. How do I log out of my Google Account in Firebase in android studio, such that when I log in again, I am allowed to choose the account I am able to sign in with. Right now, I am always being logged in with the same account.

    private GoogleSignInClient mGoogleSignInClient;

    Button btnLogout;
    FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);

        btnLogout = findViewById(R.id.btnLogout);
        mAuth=FirebaseAuth.getInstance();

        btnLogout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mAuth.signOut();
                mGoogleSignInClient.signOut();
                Intent intent = new Intent(Profile.this, SplashPage.class);
                startActivity(intent);
            }
        });
    }
}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
pigging
  • 3
  • 4
  • Do you have multiple Google accounts logged in that device? – Dharmaraj May 14 '20 at 06:05
  • Possible duplicate of [this](https://stackoverflow.com/q/33782838/13130697) – Dharmaraj May 14 '20 at 06:07
  • If you are interested in a clean Firebase authentication with Google, you can check this [article](https://medium.com/firebase-tips-tricks/how-to-create-a-clean-firebase-authentication-using-mvvm-37f9b8eb7336). Every time you log out when trying to log-in again, you'll be asked to choose the Google account. – Alex Mamo May 14 '20 at 08:50

1 Answers1

0

FirebaseAuth.getInstance().signOut() does soft sign out and if you want to be able to choose Google user again on sign in do full google sign out GoogleSignIn.getClient(activity, googleSignInOptions).signOut()

Antonis Radz
  • 3,036
  • 1
  • 16
  • 34
  • hi, when i add "GoogleSignIn.getClient(activity, googleSignInOptions).signOut()", both my "activity" and "googleSignInOptions" are red in color. – pigging May 14 '20 at 06:48
  • write code inside an activity and use `this`, or pass activity as a parameter, if it is in Fragment do getActivity(). And `googleSignInOptions` you are using somewhere already where doing google login, without it you would not be able to do login – Antonis Radz May 14 '20 at 06:54