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 ");