退出Firebase AuthUI时,请单击两次错误

时间:2018-06-06 17:09:42

标签: android firebase-authentication firebaseui

退出Firebase AuthUI时点击两次错误:

当我点击“退出”时,它会“祝你已登录。”

当我第二次点击“退出”时,它会返回SignInActivity。

MainActivity.java

case R.id.menu_sign_out:
     AuthUI.getInstance().signOut(MainActivity.this);
     startActivity(new Intent(MainActivity.this, SignInActivity.class));

SignInActiviy.java

mAuthStateListener = new FirebaseAuth.AuthStateListener()
        {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth)
            {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                Log.d(TAG, "[SignInActivity]current user:" + user);
                if (user != null)
                {
                    //user is signed in
                    Toast.makeText(SignInActivity.this, "You're signed in.", Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(SignInActivity.this, MainActivity.class));
                }
            }
        };

@Override
    protected void onPause()
    {
        super.onPause();
        if (mAuthStateListener != null)
        {
            mFirebaseAuth.removeAuthStateListener(mAuthStateListener);
        }

    }

    @Override
    protected void onResume()
    {
        super.onResume();
        mFirebaseAuth.addAuthStateListener(mAuthStateListener);
    }

1 个答案:

答案 0 :(得分:1)

使用“.addOnCompleteListener”解决问题

似乎Firebase AuthUI是异步的

所以退出后立即拨打电话

退出流程尚未完成。

AuthUI.getInstance().signOut(this)
  .addOnCompleteListener(new OnCompleteListener<Void>()
  {
    public void onComplete(@NonNull Task<Void> task)
    {
      StartActivity(new Intent(MainActivity.this, SignInActivity.class));
    }
  });