工具类
public class SerializableMap implements Serializable {
private HashMap<Integer, Boolean> map;
public HashMap<Integer, Boolean> getMap() {
return map;
}
public void setMap(HashMap<Integer, Boolean> map) {
this.map = map;
}
}
使用
//需要传递的map
HashMap<Integer, Boolean> xbksmap = new HashMap<Integer, Boolean>();
Intent intent1 = new Intent(DetailNotifiActivity2.this, XbksAlertActivity.class);
intent1.putExtra("flowname", flowname);
Log.i("gjw", "协办科室被点击");
//传递map
Bundle bundle1 = new Bundle();
SerializableMap tepmap1 = new SerializableMap();
tepmap1.setMap(xbksmap);
bundle1.putSerializable("tepmap", tepmap1);
接收map
HashMap<Integer, Boolean> isSelected= new HashMap<Integer, Boolean>();
HashMap<Integer, Boolean> tempIsSelected= new HashMap<Integer, Boolean>();
Intent intent = getIntent();
Bundle bundle = getIntent().getExtras();
SerializableMap serializableMap = (SerializableMap) bundle.get("tepmap");
//两个map相互赋值
isSelected = serializableMap.getMap();
isSelected.putAll(tempIsSelected);
本文介绍了一个名为SerializableMap的工具类,该类实现了Serializable接口,用于序列化和反序列化HashMap对象。通过具体示例展示了如何将HashMap对象封装到SerializableMap中,并通过Intent和Bundle在Android活动中进行传递。
622

被折叠的 条评论
为什么被折叠?



