Android development, in different modules (such as activity) will often have a variety of data need to communicate with each other, commonly used in five ways of delivery. They have their own pros and cons and have their own application scenarios. Here are a few separate sections:
1. Intent object passing simple data
The extra portion of the intent can store the data that is passed, and can transfer some underlying types, such as int, long, char, and so on.
[1] Delivery page:
Intent Intent = new Intent (); Intent.setclass (Mainactivity.this, Secondactivity.class); Bundle bundle = new bundle (); Package Send bundle.putstring ("name", "123"); Binding parameters Intent.putextra ("Maps", bundles); startactivity (intent);
[2] Receiving page:
@Overrideprotected void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); TextView TV = new TextView (this); Intent Intent = This.getintent (); Bundle bundle = Intent.getbundleextra ("Maps"); Gets the package data bundle String name = bundle.getstring ("name"); Remove the required data Tv.settext (name); Setcontentview (TV);} or @override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (R.layout.second); TextView txt = (TextView) This.findviewbyid (r.id.txt); Intent Intent = This.getintent (); Bundle bundle = Intent.getbundleextra ("Maps"); Gets the package data bundle String name = bundle.getstring ("name"); Remove the required data Txt.settext (name);}
2., intent objects Pass complex data
Sometimes we want to pass on complex data such as ArrayList, which is the same as the above one, except that it will be wrapped up with a new list before the parameter is passed. As follows:
Android Data Transfer Summary