Android: String set preference is not persistent

前端 未结 2 432
忘掉有多难
忘掉有多难 2020-12-11 09:00

I have a problem with storing string set preference. I have these utility methods for storing:

public static void putStringSet(SharedPreferences pref, Editor         


        
2条回答
  •  一整个雨季
    2020-12-11 09:29

    This has a ridiculous amount of duplicates - I bet that you do :

    set = prefs.getStringSet("X", new HashSet());
    set.add("yada yada");
    prefs.putStringSet("X", set);
    

    In short android sees that set and the one inside refer to the same set and does nothing. Correct ?

    See: Misbehavior when trying to store a string set using SharedPreferences

提交回复
热议问题