Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreferences reset: Map size is not 0 after reset

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;
like image 780
gosr Avatar asked Nov 24 '22 11:11

gosr


1 Answers

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.

like image 161
gabriel Avatar answered Jan 20 '23 07:01

gabriel