I'd like to save a list of buttons in SharedPreferences but it doesn't work. The error message that occurs is "java.lang.IllegalArgumentException: class android.graphics.drawable.InsetDrawable declares multiple JSON fields named mState"
public boolean writeToSharedPreferences(Context context, ArrayList<Button> arrayList) {
String file = "list";
SharedPreferences mPrefs = context.getSharedPreferences(file, Context.MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
Gson gson = new Gson();
String json = gson.toJson(arrayList);
prefsEditor.putString("list", json);
prefsEditor.commit();
return true;
}
public ArrayList<Button> readFromSharedPreferences(Context context) {
String file = "list";
SharedPreferences mPrefs = context.getSharedPreferences(file, Context.MODE_PRIVATE);
Gson gson = new Gson();
String json = mPrefs.getString("list", "");
Type type = new TypeToken<List<Button>>(){}.getType();
ArrayList<Button> arrayList= gson.fromJson(json, type);
return arrayList;
}
Can someone help me pls?