I want my application to delete all preferences when the user logs out and bring up the LoginActivity
after exiting the main screen. I've been following the suggestions here. In my way, I get only the default preferences.
The workflow of my app goes this way if it helps:
Login -> Save User Details to Preferences -> Start MainActivity
-> Logout -> Clear Preferences -> Start LoginActivity
Is the problem caused by using the default preferences? Or is it because I called finish()? I've tried apply()
and commit()
. Neither worked. The preferences still exist when I tried accessing them in the LoginActivity
. How do I clear my preferences?
private void logout(){
// clear preferences
SharedPreferences sharedPreferences = this.getPreferences(Context.MODE_PRIVATE);
sharedPreferences.edit().clear().apply();
Intent i = new Intent(this, LoginActivity.class);
startActivity(i); // call LoginActivity and finish this one.
finish();
}