Created
March 13, 2014 08:38
-
-
Save nguyenhuy/9524446 to your computer and use it in GitHub Desktop.
Save a set of strings to SharedPreferences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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