Transfer parameters between Android learning Note--activity

Source: Internet
Author: User

Intent i = new Intent (curractivity.this, Anotheractivity.class);

I.putextra ("name", "Here you can pass in a variety of common data types,include bundlesIn Anotheractivity, the intent iintent i = getintent () can be obtained through the Getintent () method curractivity. String name = I.getstringextra ("name"), or//to get different types of extra based on the data type passed in, here is a string so use Getstringextra. It is also possible to pass multiple data at once by passing bundles Intent i = new Intent (curractivity.this, Anotheractivity.class);     Bundle B = new Bundle (), b.putstring ("name", "Crazybun"), B.putint ("age", 24), there are two ways to pass bundles: I.putextra ("Bundle", b); Use I.get when fetchingBundleExtra ("bundle"); I.putextras(b); Use I.getextra when fetchings(); Then in Anotheractivity//First getintent () gets intentintent i = getintent ();//get bundlebundle B = I.getextra from Is();//after which data is taken from B, string name = B.getstring ("name"); String age = B.getint ("Age");//To prevent a key-value pair from being obtained, you can add a parameter to the Get () method that represents the default value, such as:String father = b.getstring ("Father", "Bun");in this case, if there is no father this key value pair in the bundle, the father will be assigned to Bun .

Transfer parameters between Android learning Note--activity

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.