Storing Arraylist Go Objects In Sharedpreference
I have an Arraylist of objects. Each time I press a button, I create an object and place it in the ArrayList. I need to save this array list when I exit the app. When I come and a
Solution 1:
GSON is very easy to use, look here: How Android SharedPreferences save/store object
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE); To Save
EditorprefsEditor= mPrefs.edit();
Gsongson=newGson();
Stringjson= gson.toJson(MyObject);
prefsEditor.putString("MyObject", json);
prefsEditor.commit();
To Retreive
Gsongson=newGson();
Stringjson= mPrefs.getString("MyObject", "");
MyObjectobj= gson.fromJson(json, MyObject.class);
Post a Comment for "Storing Arraylist Go Objects In Sharedpreference"