FirebaseAuth.getInstance().signOut() doesn't signout

眉间皱痕 提交于 2021-02-11 08:12:03

问题


I try to signout user from firebase but after i close my app and open again the user is stills connect

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

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

        }
    }

回答1:


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

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.

If it is working let me know.

Hope this will help you. Thanks




回答2:


I think you are being logged out correctly but as you are moving to

LoginActivity.class

Where you might be logging the user back in again you would have to make certain changes in Login activity.



来源:https://stackoverflow.com/questions/56337887/firebaseauth-getinstance-signout-doesnt-signout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!