clear data from shared pref in android app
As i am new to android development.
After user clicks on sign out button from my app i want to delete all the info which i have stored in shared pref.
i used this editor.clear()
but it won't work,
I want to delete that XML file which i开发者_StackOverflow社区s created by shared pref after user clicks on log out button i want to delete that file at run time?
thnx for any help....
You need to commit your changes:
editor.clear();
editor.commit();
Hoper this help
Try editor.clear();
followed by a editor.commit();
Edit:
Here is one example that I've used:
Preference clearPref = (Preference) findPreference("clearAll");
clearPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = settings.edit();
editor.clear();
editor.commit();
Toast.makeText(getBaseContext(), "All data cleared!", Toast.LENGTH_SHORT).show();
return true;
}
});
精彩评论