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