In Android, Intent has two types of values on two pages. One is to transfer values between two activities, and the other is to transfer data between a common page and an Activity.
1. Intent transfers values between two activities
First define two activities FirstActivity and SecondActivity
Code in the onCreate () method of FirstActivity
Intent intent = new Intent ();
String str = "data to be passed ";
Intent. putExtra ("str", str );
Intent. setClass (FirstActivity. this, SecondActivity. class );
StartActivity (intent );
On the SecondActivity page
Intent intent = getIntent ();
Intent. getStringExtra ("str ");
2. Intent transmits data between a common page and an Activity
The two pages are MainActivity and Intention. java.
Code in the onCreate () method of MainActivity
Intent intent = new Intent ();
String str = "data to be passed ";
Intent. putExtra ("str", str );
Intent. setClass (context, SecondActivity. class );
Context. startActivity (intent );
The code in Intention. java is
Intent intent = getIntent ();
Intent. getStringExtra ("str ");