Activity jumps and passes values. Mainly through the intent class. The role of intent is to activate the component and the accompanying data.
First, activity jumps
Method One
Intent Intent = new Intent (a.this, B.class);
StartActivity (Intent)
Method Two
Intent Intent = new Intent ();
Intent.setclass (A.this, B.class);
StartActivity (Intent);
Implementation from a jump to B (A, B are inherited from activity)
II. Transmission of data
Activity A transmits data
Method One
Intent Intent = new Intent ();
Intent.setclass (A.this, B.class);
Intent.putextra ("name", "XY");
Intent.putextra ("Age", 22);
StartActivity (Intent);
Method Two
Intent Intent = new Intent (a.this, B.class);
Bundle bundle = new bundle ();
Bundle.putstring ("name", "XY");
Bundle.putint ("Age", 22);
Intent.putextras (bundle);
StartActivity (Intent);
Activity B receives data
Get the number of references 1
Intent Intent = This.getintent ();
String name = Intent.getstringextra ("name");
int age = Intent.getintextra ("Age", 22); The default value is 22
Get the number of references 2
Bundle bundle = Intent.getextras ();
String name2 = bundle.getstring ("name");
int age2 = Bundle.getint ("Age", 22);
Both of these can be obtained, not with the corresponding method one by one.
Android Learning activity jump and transfer value