Android Data Transfer Summary

Source: Internet
Author: User

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

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.