Google Firebase sign out and forget user in Android app

For anyone else who wants this result (as in getting the google account options back) on a different activity.

public static void signOut() {
    // Firebase sign out
    mAuth.signOut();

    // Google sign out
    Auth.GoogleSignInApi.signOut(mGoogleApiClient);
}

Add this on the sign in page, and before you pass to the next activity, just call SignOut().

// everything ok...             
signOut();
startActivity(new Intent(SignIn.this,NextOne.class));

and then, in your other class you can call

FirebaseAuth.getInstance().signOut();
startActivity(new Intent(NextClass.this, SignIn.class));

It's easy, and it will work. Cheers!


I was confused since all of the solutions required having a reference to the GoogleSignInClient, but it is actually not required for you to hold a reference to it, you can simply create a new instance and call signOut() on it.

GoogleSignIn.getClient(
    getContext(), 
    new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build()
).signOut();

In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut() when you sign-out?

private void signOut() {
    // Firebase sign out
    mAuth.signOut();

    // Google sign out
    mGoogleSignInClient.signOut().addOnCompleteListener(this,
            new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    updateUI(null);
                }
            });
}

Another option is to use the FirebaseUI library. It simplifies sign in and sign out operations in a sense that it will do all the heavy lifting for you.

Kotlin

AuthUI.getInstance().signOut(this).addOnCompleteListener { 
    // do something here 
}

Java

AuthUI.getInstance()
      .signOut(ActivityMainOld.this)
      .addOnCompleteListener(new OnCompleteListener<Void>(){

          @Override
          public void onComplete(@NonNull Task<Void> task) {

              // do something here

          }
      });

Hope this helps