[英]FirebaseAuth.getInstance().signOut() doesn't signout
我尝试从Firebase注销用户,但是在我关闭应用程序并再次打开后,该用户仍然处于连接状态
我尝试从Firebase常规注销用户,但无法解决问题。 我想知道是什么原因引起的
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FirebaseAuth.getInstance().signOut();
Intent picture_intent = new Intent(Dashboard.this,LoginActivity.class);
startActivity(picture_intent );
}
});
我检查用户是否连接:
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser currentUser = firebaseAuth.getCurrentUser();
if(currentUser != null)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
int again = preferences.getInt(String.valueOf(R.string.remember_me), 0);
if(again == 0)
{
Intent i = new Intent(getApplicationContext(), PagerActivity.class);
startActivity(i);
}
else
{
Intent i = new Intent(getApplicationContext(), Dashboard.class);
startActivity(i);
}
}
}
我认为您已正确注销,但是随着
LoginActivity.class
在可能再次登录用户的位置,您必须在“登录”活动中进行某些更改。
为什么要使用SharedPreferences? 如果您要使用Firebase维护会话,则不需要sharedpreferences。 顺便说一下,您的代码似乎是正确的。 调用注销函数后,请尝试进行以下修改。
FirebaseAuth.getInstance().signOut();
Intent intent = new Intent(getActivity(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
并完全删除您的onAuthStateChanged()方法(因为我看不到完整的代码,可能是您弄乱了该方法中的内容),因此仅出于测试目的删除此方法,并按照我的意愿将标志添加到您的意图中。
如果工作正常,请告诉我。
希望这会帮助你。 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.