简体   繁体   中英

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

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

        }
    }

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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