简体   繁体   English

FirebaseAuth.getInstance()。signOut()未注销

[英]FirebaseAuth.getInstance().signOut() doesn't signout

I try to signout user from firebase but after i close my app and open again the user is stills connect 我尝试从Firebase注销用户,但是在我关闭应用程序并再次打开后,该用户仍然处于连接状态

I tried the regular signout of user from firebase and it not solve the problem. 我尝试从Firebase常规注销用户,但无法解决问题。 I am wondering what could cause the problem 我想知道是什么原因引起的

 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 );
            }
        });

my check if user connect: 我检查用户是否连接:

@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);
            }

        }
    }

I think you are being logged out correctly but as you are moving to 我认为您已正确注销,但是随着

LoginActivity.class LoginActivity.class

Where you might be logging the user back in again you would have to make certain changes in Login activity. 在可能再次登录用户的位置,您必须在“登录”活动中进行某些更改。

Why you are using SharedPreferences? 为什么要使用SharedPreferences? If you are maintaining the session with firebase you don't need sharedpreferences. 如果您要使用Firebase维护会话,则不需要sharedpreferences。 By the way your code seems correct. 顺便说一下,您的代码似乎是正确的。 Try doing the following modification with your intent after calling the logout function. 调用注销函数后,请尝试进行以下修改。

FirebaseAuth.getInstance().signOut();    
Intent intent = new Intent(getActivity(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

And completely delete your onAuthStateChanged() method (Because I cannot see your complete code, and may be you are messing the things inside this method) so just for testing remove this method, and add the flags to your intent as I said. 并完全删除您的onAuthStateChanged()方法(因为我看不到完整的代码,可能是您弄乱了该方法中的内容),因此仅出于测试目的删除此方法,并按照我的意愿将标志添加到您的意图中。

If it is working let me know. 如果工作正常,请告诉我。

Hope this will help you. 希望这会帮助你。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM