I have an android app with a number of activities, and a number of specific preference files that are created. When a user sign out of my app, I want to delete absolutely all shared preferences. Understand that I cannot use context.getSharedPreferences("A_PREFS_FILE", 0).edit().clear().commit()
as that would only clear one specific file. I want to clear all the preference files associated with my app. Is there a way to do that?
By this way you can delete all the files at ones.. by clear() it will erase the data file still exist..
File sharedPreferenceFile = new File("/data/data/"+ getPackageName()+ "/shared_prefs/");
File[] listFiles = sharedPreferenceFile.listFiles();
for (File file : listFiles) {
file.delete();
}
Here it will returns the all the list of files then you can easily delete..
This works
public static void deleteAllDataInSharedPreference(Context context){
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();
context = null;
}
deleteAllDataInSharedPreference(getApplicationContext());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With