转自:http://my.oschina.net/baishi/blog/182931
android开发默认情况下,通过Bundle bundle=new Bundle();传递值是不能直接传递map对象的,解决办法:
第一步:封装自己的map,实现序列化即可
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/**
* 序列化map供Bundle传递map使用
* Created on 13-12-9.
*/
public
class
SerializableMap
implements
Serializable {
private
Map<String,Object> map;
public
Map<String, Object> getMap() {
return
map;
}
public
void
setMap(Map<String, Object> map) {
this
.map = map;
}
}
|
第二步:传递数据:
1
2
3
4
5
6
7
|
Intent intent=
new
Intent(ListViewActivity.
this
,UpdateWatchActivity.
class
);
//传递数据
final SerializableMap myMap=
new
SerializableMap();
myMap.setMap(map);
//将map数据添加到封装的myMap<span></span>中
Bundle bundle=
new
Bundle();
bundle.putSerializable(
"map"
, myMap);
intent.putExtras(bundle);
|
第三步:接收数据:
1
2
|
Bundle bundle = getIntent().getExtras();
SerializableMap serializableMap = (SerializableMap) bundle.get(
"map"
);
|