Android ArrayList of custom objects – Save to SharedPreferences – Serializable?
Yes, you can save your composite object in shared preferences. Let’s say.. Student mStudentObject = new Student(); SharedPreferences appSharedPrefs = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); Editor prefsEditor = appSharedPrefs.edit(); Gson gson = new Gson(); String json = gson.toJson(mStudentObject); prefsEditor.putString(“MyObject”, json); prefsEditor.commit(); ..and now you can retrieve your object as: SharedPreferences appSharedPrefs = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); Gson gson = new … Read more