Intent 传递Map数据

android开发默认情况下,通过Bundle bundle=new Bundle();传递值是不能直接传递map对象的,解决办法:

第一步:封装自己的map,实现序列化即可 

/**
 *序列化map供Bundle传递map使用
 */
@SuppressWarnings("serial")
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;
    }
}

第二步:传递数据:

        Bundle bundle1 = new Bundle();
        SerializableMap Mymap=new SerializableMap();
        Mymap.setMap(servicemsg);
        bundle1.putSerializable("servicemsg", Mymap);
        startActivity(ServiceMessageActivity.class, bundle1);

第三步:接收数据:

        Bundle extras = getIntent().getExtras();
        SerializableMap serializable = (SerializableMap) extras.getSerializable("servicemsg");
        Map<String, Object> map = serializable.getMap();

 

posted @ 2015-04-30 18:34  用户没有名  阅读(1217)  评论(0编辑  收藏  举报