存
List<MyRecords> listDate=new ArrayList<MyRecords>();
MyRecords myRecords=new MyRecords(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(date * 1000)),String.valueOf(heart));
listDate.add(myRecords);
Gson gson = new Gson();
String jsonMyRecords = gson.toJson(listDate);
LogUtil.i(TAG, "json====" + jsonMyRecords);
DeviceUtil.setPreferences(getApplicationContext(), "jsonMyRecords", jsonMyRecords);
取
String jsonMyRecords = DeviceUtil.getPreferences(this, "jsonMyRecords", null);
if (jsonMyRecords != null) {
Gson gson = new Gson();
Type type = new TypeToken<List<MyRecords>>(){}.getType();
List<MyRecords> listMyRecords = new ArrayList<MyRecords>();
listMyRecords = gson.fromJson(jsonMyRecords, type);
for(int i = 0; i < listMyRecords.size(); i++)
{
allRecords.add(listMyRecords.get(i));
}
}