问题
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