Android Parcelable序列化自定义类集合在Activity间传递
读取
参考链接 https://blog.csdn.net/haishizi1/article/details/84420576
// 将Map Key 转化为List
List<String> mapKeyList = new ArrayList<String>(map.keySet());
System.out.println("mapKeyList:"+mapKeyList);
// 将Map value转化为List
List<String> mapValuesList = new ArrayList<String>(map.values());
System.out.println("mapValuesList:"+mapValuesList);
Intent 传递map 利用gson 将map转为string
private String seven() {
Gson gson2 = new GsonBuilder().enableComplexMapKeySerialization().create();
Map<String, String> map = new HashMap<String, String>();
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
return gson2.toJson(map);
}
获取string ,转为map对象
Type type = new TypeToken<Map<String, String>>() {}.getType();
Map<String, String> map2 = gson2.fromJson(jsonString, type);
Intent 传递List ,对象实现Parcelable接口
intent.putExtra("change_data", (ArrayList<? extends Parcelable>) listData);
获取list对象