Intent (3) transmits data to the next activity, and intent transmits data
The downward transfer activity is very simple. You can use the putExtra () method to reload the data that we want to transfer to intent temporarily. You can retrieve the data from this when starting the activity.
First, we start SecondActivity by explicitly declaring intent in MainActivity (main activity) and pass data through PutExtra. Note that this method has two parameters: [keyName, vule]: The first parameter is the row parameter, and the second parameter is the real parameter;
String str_info = "putExtra transfers data"; Intent intent = new Intent (MainActivity. this, SecondActivity. class); intent. putExtra ("extra_data", str_info); startActivity (intent );
Then we get the Intent used to start SecondActivity through the getIntent () method in SecondActivity and call getStringExtra (keyName) to get the value passed in the previous activity. Note: getStringExtra () if there are multiple types of overloaded int values, use getIntExtra, and use getBoolExtra () for bool ().
Intent intent =getIntent(); String data=intent.getStringExtra("extra_data"); Log.d("SecondActivity",data) ;
Today, we will continue to share "return data to the previous activity" tomorrow night"