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

查看:52
本文介绍了FirebaseAuth.getInstance().signOut()未注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Firebase中注销用户,但是在我关闭我的应用程序并再次打开后,该用户仍然是连接

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

我检查用户是否连接:

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

        }
    }

推荐答案

为什么要使用SharedPreferences?如果您要使用Firebase维护会话,则不需要sharedpreferences.顺便说一句,您的代码似乎是正确的.调用注销函数后,请尝试进行以下修改.

Why you are using SharedPreferences? If you are maintaining the session with firebase you don't need 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);

并完全删除您的 onAuthStateChanged()方法(因为我看不到您的完整代码,可能是您弄乱了该方法中的内容),因此为了进行测试,请删除该方法,并添加就像我说的那样标记您的意图.

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.

如果可以,请告诉我.

希望这会对您有所帮助.谢谢

Hope this will help you. Thanks

这篇关于FirebaseAuth.getInstance().signOut()未注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆