Android持久自定义对象包含图像,日期等

时间:2018-04-27 23:46:47

标签: android object save sharedpreferences persistence

我有一个对象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;
    }
}

0 个答案:

没有答案
相关问题