title: Firebase Auth cannot sign out using Android
body: <p>I am totally new to Android and firebase and I am having some issues when I try to sign out from Firebase.</p>
  
  <p>A piece of my code is following at the bottom..</p>
  
  <p>In the onAuthStateChanged listener I try to create a Firebase user and get the current user in order to check if it is NOT null (which according to the Firebase docs means the user is signed in) or null which means the user is not signed in..</p>
  
  <p>Then comes the problem.. </p>
  
  <p>Out of testing / curiosity purposes, if the user is signed in, I try to update the user profile and set a custom display name.. to see what happens.</p>
  
  <p>It appears that after updating the profile and more specifically the line 
  "user.updateProfile(profileUpdates);" breaks the signout() function.</p>
  
  <p>If I comment out the line "user.updateProfile(profileUpdates);" the signout() function seems to be working fine!</p>
  
  <p>Can you point out what am I doing wrong?</p>
  
  <p>Are there duplicate instances of the firebase user somewhere?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  private FirebaseAuth FireAuth;
  private FirebaseAuth.AuthStateListener mAuthListener;
  private FirebaseDatabase mFireDatabase;
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
      FireAuth = FirebaseAuth.getInstance();
  
      mAuthListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
  
              FirebaseUser user = firebaseAuth.getCurrentUser();
  
              if (user != null) {
                  // already signed in
                  UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                          .setDisplayName("SuperMan").build();
                  user.updateProfile(profileUpdates); // This breaks it!
                  signoutButton.setText(user.getDisplayName().toString());
  
              } else {
                  // not signed in
  
              }
  
          }
      };
  
  }
  
  public void signin(String email, String password){
  
     FireAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
          @Override
          public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
              Log.d("myTEST","signInWithEmailAndPassword:complete:"+task.isSuccessful());
          }
      });
  }
  private void signout(){
      //FireAuth.getInstance().signOut();
      FireAuth.signOut();
  
  }
  
  public void getDisplayName(){
  
      if (FireAuth.getCurrentUser() !=null){
          UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
                  .setDisplayName("SuperMan").build();
  
          FireAuth.getCurrentUser().updateProfile(profileUpdates);
          signoutButton.setText(FireAuth.getCurrentUser().getUid().toString());
          if(FireAuth.getCurrentUser().isAnonymous()){
              signoutButton.setText("Anonymous");
          }
  
      }else{
          signoutButton.setText("empty..");
      }
  }
  
  
  @Override
  public void onStart() {
      super.onStart();
      FireAuth.addAuthStateListener(mAuthListener);
  }
  
  @Override
  public void onStop(){
      super.onStop();
      FireAuth.removeAuthStateListener(mAuthListener);
  }
  
  
  @Override
  public void onClick(View v){
      switch (v.getId()){
          case R.id.signinButton:
              signin(loginEditText.getText().toString(),passwordEditText.getText().toString());
          break;
          case R.id.signoutButton:
              signout();
          break;
          case R.id.button3:
              getDisplayName();
              break;
  
      }
  
  }}
  </code></pre>