diff --git a/mobile/android/base/preferences/MultiChoicePreference.java b/mobile/android/base/preferences/MultiChoicePreference.java index 34dc4811417c..375f402e7088 100644 --- a/mobile/android/base/preferences/MultiChoicePreference.java +++ b/mobile/android/base/preferences/MultiChoicePreference.java @@ -219,7 +219,7 @@ class MultiChoicePreference extends DialogPreference implements DialogInterface. protected boolean persist(SharedPreferences.Editor edit) { if (isPersistent()) { Set vals = getValues(); - PrefUtils.putStringSet(edit, getKey(), vals); + PrefUtils.putStringSet(edit, getKey(), vals).apply();; return true; } diff --git a/mobile/android/base/util/PrefUtils.java b/mobile/android/base/util/PrefUtils.java index 7a48d41bd3df..499538b80e56 100644 --- a/mobile/android/base/util/PrefUtils.java +++ b/mobile/android/base/util/PrefUtils.java @@ -54,19 +54,27 @@ public class PrefUtils { return new HashSet(); } - // Cross version compatible way to save a string set to a pref. - // NOTE: The editor that is passed in will not commit the transaction for you. It is up to callers to commit - // when they are done with any other changes to the database. - public static SharedPreferences.Editor putStringSet(final SharedPreferences.Editor edit, + /** + * Cross version compatible way to save a set of strings. + *

+ * This method does not commit any transaction. It is up to callers + * to commit. + * + * @param editor to write to. + * @param key to write. + * @param vals comprising string set. + * @return + */ + public static SharedPreferences.Editor putStringSet(final SharedPreferences.Editor editor, final String key, final Set vals) { if (Versions.preHC) { final JSONArray json = new JSONArray(vals); - edit.putString(key, json.toString()).apply(); + editor.putString(key, json.toString()); } else { - edit.putStringSet(key, vals).apply(); + editor.putStringSet(key, vals); } - return edit; + return editor; } }