我的应用同时使用电子邮件和Google Auth。如果用户注销并尝试登录,则会出现问题。应用程序关闭,再次单击时打开,用户登录。如果我从登录屏幕按下后退按钮并退出应用程序,则再次启动时按预期工作。 这是我用于退出的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.getOut) {
mFirebaseAuth.getInstance().signOut();
DetachReadListener();
finishAffinity();
return true;
}
return super.onOptionsItemSelected(item);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SING_IN) {
if (resultCode==RESULT_CANCELED) {
finishAffinity();
}
}
}
Android Monitor没有显示错误,所以我对此没有任何线索。请帮我解决这个错误。
谢谢!
我的登录代码:
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = mFirebaseAuth.getCurrentUser();
if (user!=null) {
uid = user.getUid();
if (user.getPhotoUrl()!=null) {
avatarurl = user.getPhotoUrl().toString();
RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getApplicationContext().getResources(),getImageBitmap(avatarurl));
drawable.setCircular(true);
imgavatar.setImageDrawable(drawable);
// imgavatar.setImageBitmap(getImageBitmap(avatarurl));
} else
imgavatar.setImageResource(R.drawable.ic_account_black_48dp);
mUsername = user.getDisplayName();
username.setText(mUsername);
AttachReadListener();
DatabaseReference usruid = usersref.child(uid).child("flag");
usruid.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
while (!dataSnapshot.exists()) {
pb.setContentView(R.layout.activity_progress_bar);
pb.requestWindowFeature(Window.FEATURE_NO_TITLE);
pb.show();
}
val = dataSnapshot.getValue(String.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setTheme(R.style.LoginTheme)
.setLogo(R.drawable.firstlogo)
.setAvailableProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
.build(), RC_SING_IN
);
}
}
};
答案 0 :(得分:0)
正如您所说的,您同时使用电子邮件和Google登录。因此,如果用户使用电子邮件方法登录,请使用FirebaseAuth.getInstance().signOut()
。
如果用户使用google登录登录,则可以从 Google登录和 Firebase 退出用户,例如:
googleSignInClient.signOut().addOnCompleteListener(this,
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
// firebase sign out
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(SignOutActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
});