Activity jump and value passing mainly connects multiple activities through the Intent class and transmits data through the Bundle class.
The sample code is as follows:
1.1 assign values using the intent. putExtra () method
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
1 Bundle bundle = this. getIntent (). getExtras ();
2 String flg = bundle. getString ("flg ");
3 if (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.
1 Bundle bundle = new Bundle ();
2
3 bundle. putString ("Name", "Jacker ");
4 bundle. putString ("Phone", "13590010101 ");
5 bundle. putBoolean ("flg", true );
6
7 intent. putExtras (bundle );
2.2 The same method is used to obtain the passed Value
1 Bundle bundle = this. getIntent (). getExtras ();
2
3 String name = bundle. getString ("Name ");
4 String phone = bundle. getString ("Phone ");
5 boolean flg = bundle. getBoolean ("flg ");