Base of Android program development-page value passing

Source: Internet
Author: User

Activity jump and value passing mainly connects multiple activities through the intent class and transmits data through the bundle class.

ExampleCodeAs follows:

 

1.1 UseIntent. putextra () Method assignment

 1   Public   Class Menu Extends  Activity {  2   3   @ Override  4       Public   Void Oncreate (bundle savedinstancestate ){  5           Super  . Oncreate (savedinstancestate );  6   7   Setcontentview (R. layout. Menu );  8   9   ...  10   11           //  Button2  12 Button btn2 =(Button) findviewbyid (R. Id. button2 );  13   14 Btn2.setonclicklistener ( New  Onclicklistener (){  15   16   @ Override  17               Public   Void  Onclick (view arg0 ){  18   19 Intent intent = New Intent (menu. This , Detail. Class  );  20 Intent. putextra ("flg", "list" );  21   Startactivity (intent );  22   }  23   });  24   25   ...  26          27   28 }

 

 

 

1.2. Get the value on another page

 
1Bundle bundle =This. Getintent (). getextras ();2String flg = bundle. getstring ("flg");3If(Flg. Equals ("list")){4 ...5}

 

 

2.1 If You Want To transmit a set of data, you must use the bundle object to transmit data.

 
1Bundle bundle =NewBundle ();2 3Bundle. putstring ("name", "jacker");4Bundle. putstring ("phone", "13590010101");5Bundle. putboolean ("flg ",True);6 7Intent. putextras (bundle );

 

2.2 The same method is used to obtain the passed Value

1Bundle bundle =This. Getintent (). getextras ();2 3String name = bundle. getstring ("name");4String phone = bundle. getstring ("phone");5BooleanFlg = bundle. getboolean ("flg ");

 

Related Article

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.