I have an ArrayList
of objects that have a name and an icon pointer and I want to save it in SharedPreferences
. How can I do?
NOTE:
You can use putStringSet
This allow you to save a HashSet in your preferences, just like this:
Save
Set values;
SharedPreferences sharedPref =
mContext.getSharedPreferences(PREF_KEY, Context.MODE_PRIVATE);
Editor editor = sharedPref.edit();
editor.putStringSet("YOUR_KEY", values);
editor.apply();
Retrive
SharedPreferences sharedPref =
mContext.getSharedPreferences(PREF_KEY, Context.MODE_PRIVATE);
Editor editor = sharedPref.edit();
Set newList = editor.getStringSet("YOUR_KEY", null);
The putStringSet allow just a Set and this is an unordered list.