Skip to content

Instantly share code, notes, and snippets.

@nguyenhuy
Created March 13, 2014 08:38
Show Gist options
  • Save nguyenhuy/9524446 to your computer and use it in GitHub Desktop.
Save nguyenhuy/9524446 to your computer and use it in GitHub Desktop.
Save a set of strings to SharedPreferences
public void setStringSet(int keyResId, Set<String> values) {
String key = mContext.getString(keyResId);
SharedPreferences.Editor editor = mSharedPreferences.edit();
if (Build.VERSION.SDK_INT >= 11) {
editor.putStringSet(key, values);
} else {
Gson gson = new Gson();
String jsonValue = gson.toJson(values);
editor.putString(key, value);
}
editor.apply();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment