In development, we often use the activity, then since the use of activity, it is inevitable to pass data between the two activity. Here we first talk about the principle, look at the code and examples.
Situation A: We need to start and pass data from Activity_1 to activity_2,activity_2 only to receive data from Activity_1, but not for other operations.
Case B: We need to start activity_2 from Activity_1, and want Activity_2 to pass the data to Activity_1 when it is destroyed.
First of all, let's say a.
Situation A is relatively simple, in fact, activity_1 use Intent's Putextra () method to carry the data, and then activity_2 through the intent () method to obtain Getextra passed over the data.
Situation B is a little more troublesome, but it is also very simple. is to use the Startactivityforresult () method to start Activity_2, and then activity_2 use the intent and Setresult () methods to transfer data to activity_1, and finally, activity_ 1 receive activity_2 Data via callback method Onactivityresult ().
Data transfer between activity in Android Ngti