title: Android Firebase Gmail Log out
body: <p>I am using Firebase to log in users using their Google accounts. On my phone I have three Gmail account so when I press Google sign in button (which is in SignInActivity.java which is activity that is always opened first) I am given an option to chose between those three accounts, I pick one and I am logged in my app. I have added the button to log out current user and it does this:</p>
  
  <pre><code>FirestoreUtil.firebaseAuth.addAuthStateListener { firebaseAuth -&gt;
              if(firebaseAuth.currentUser == null){
                  Log.i("logout", "logout complete current user = null")
                  val intent = Intent(mContext, SignInActivity::class.java)
                  intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
                  startActivity(intent)
                  activity?.finish()
              }else{
                  Log.i("logout", "current user != null = ${firebaseAuth.currentUser}")
              }
          }
          FirestoreUtil.firebaseAuth.signOut()
  </code></pre>
  
  <p>I call <code>firebaseAuth.signOut()</code> and use a listener to know when user has been successfully logged out, I then create an Intent with <code>SignInActivity.java</code> (which is the main activity that has google signin button) and I put some flags to clear tasks and I start new activity and finish current.</p>
  
  <p>This gives me the weirdest behaviour:</p>
  
  <ol>
  <li>First of all when I am returned to SignInActivity and I press
  GoogleSignIn button I don't get the option to choose between three
  account that I have, instead I am logged back in with the account I
  used previously (The point of logout is you choose different account
  not the same ! )</li>
  <li>Another problem is that after I press logout button I am returned
  back to SignInActivity, but if I then exit the app and come back I am
  sometimes returned back as logged user and sometimes I am show that
  same login screen with sign in button, I don't know what is wrong
  with that</li>
  </ol>
  
  <p>Does anyone know what is happening, am I doing the logout process wrong (I use the same functions from official documentation), why am I not getting the option to choose between accounts, what can be the cause of the weird behaviour when I am sometimes logged automatically and sometimes not.</p>