I'm tryin to use Sharedpreferences to save an arraylist of objects, but toJson and fromJson are causing fatal exceptions

前端 未结 2 1232
时光说笑
时光说笑 2021-01-16 09:01

My object contains a String, long, and int. Object is called Tracker and I have an arrayList of Trackers. When I try to use toJson i get an error. The same with fromJson.

2条回答
  •  花落未央
    2021-01-16 09:30

    You can take a look at my SharedPreferences helper

    // Save list object to another SharedPreference
    SharedPreferencesManager.getInstance(AnotherPreferenceName).putValue("guns", guns);
    List datas = SharedPreferencesManager.getInstance(AnotherPreferenceName).getValues("guns", Gun[].class); // get list object
    

提交回复
热议问题