我有一个对象Plant
,我一直试图坚持使用Gson和SharedPreferences。我遇到了问题因为Plant
里面有日期和图片。我应该如何(或不使用)Gson存储它?当应用关闭时,我会尝试保存ArrayList<Plant>
,然后在应用启动时将其恢复。这是我的植物类
public class Plant {
private String name;
private String date;
private Drawable image;
private String waterFrequency;
private Gson gson;
public Plant(String n, Drawable i, String wF){
this.name = n;
gson = new Gson();
Date time = Calendar.getInstance().getTime();
this.date = gson.toJson(time);
this.image = i;
this.waterFrequency = wF;
}
}