I'm trying to delete my SharedPreferences
, but it's not working: size
is not set to 0 as I would expect.
SharedPreferences sp = context.getSharedPreferences(name, mode);
SharedPreferences.Editor e = sp.edit();
e.clear();
e.commit();
Map<String, ?> map = sp.getAll();
int size = map.size();
Any suggestions?
private static String name = "ABC_PREFS";
private static int mode = Context.MODE_PRIVATE;
Your code looks fine from reading through it. Are you sure that context variable is initialized properly? Are other SharedPreferences variables pointing to the same file perhaps?
If these are not the problem, please consider taking a minimal sample app and paste this code in to see if it still fails. It is easier to fix a problem like this with the complete app than with just a code snippet.
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