I've been loading and saving a Set<String>
to the Android's SharedPreferences
and it seemed to be working alright until I tested killing the application
and realized the string set is not saved.
Set<String> stringSet = sharedPreferences.getStringSet(Constants.PREF_SHOULD_LOAD_SET, null);
if (stringSet != null) {
if (stringSet.contains(data)) {
stringSet.remove(data);
} else {
stringSet.add(data);
}
...
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putStringSet(Constants.PREF_SHOULD_LOAD_SET, stringSet);
editor.apply();
}
Some things I've tried:
- Using commit (instead of apply)
- Looking at other places that might be changing the value
- Debugging and looking if the value is saved