白衣非少年
要添加到@MuhammadAamirALi的答案,可以使用gson保存和检索对象列表将用户定义对象的列表保存到SharedPreferencespublic static final String KEY_CONNECTIONS = "KEY_CONNECTIONS";SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
User entity = new User();// ... set entity fieldsList connections = entity.getConnections();
// convert java object to JSON format,
// and returned as JSON formatted stringString connectionsJSONString = new Gson().toJson(connections);
editor.putString(KEY_CONNECTIONS, connectionsJSONString);editor.commit();从SharedPreferences获取用户定义对象的列表String connectionsJSONString = getPreferences(MODE_PRIVATE).getString(KEY_CONNECTIONS, null);
Type type = new TypeToken > () {}.getType();
List connections = new Gson().fromJson(connectionsJSONString, type);