Android Pass Data bundle encapsulation Pass Map object

Source: Internet
Author: User

Android development by default, the bundle bundle=new bundle (); The pass-through value cannot be passed directly to the map object, but the workaround:

The first step: encapsulate your own map to enable serialization

?
12345678910111213141516 /** * 序列化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;    }}

Step Two: Pass the data:

?
1234567 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);

Step three: Receive data:

?
12 Bundle bundle = getIntent().getExtras();        SerializableMap serializableMap = (SerializableMap) bundle.get("map");

This data can be passed and used through the map.

Android Pass Data bundle encapsulation Pass Map object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.