Activity jumps and transfers values mainly through the Intent class. Intent is used to activate components and accompanying data.
1. Activity jump
Method 1
Intent intent = new Intent (A. this, B. class );
StartActivity (intent)
Method 2
Intent intent = new Intent ();
Intent. setClass (A. this, B. class );
StartActivity (intent );
Implement jump from A to B (A and B are inherited from Activity)
Ii. Data Transmission
Activity A transmits data
Method 1
Intent intent = new Intent ();
Intent. setClass (A. this, B. class );
Intent. putExtra ("name", "xy ");
Intent. putExtra ("age", 22 );
StartActivity (intent );
Method 2
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
// Obtain parameter 1
Intent intent = this. getIntent ();
String name = intent. getStringExtra ("name ");
Int age = intent. getIntExtra ("age", 22); // The default value is 22.
// Obtain parameter 2
Bundle bundle = intent. getExtras ();
String name2 = bundle. getString ("name ");
Int age2 = bundle. getInt ("age", 22 );
Both methods can be used to obtain parameters. They are not exactly the same as the method for passing parameters 1 and 2.