prerequisites: Call relationships between activities: A --> B, that is, activity a starts the Code of Activity B in activity: startactivityforresult (new intent ("activityb"), 100)
the most important difference between this method and startactivity (intent) is that this method has returned values, the returned value is actually: The activity you started calls the finish () method or press the back key to get rid of destory (), and then there will be a return value. If you want to use the returned information, you must use the onactivityresult (INT requestcode, int resultcode, intent
data) method of the override parent class in your previous activity, after activityb is destroyed, the onactivityresult (INT requestcode, int resultcode, intent data) method in a is automatically executed. The requestcode is the requestcode you used to call B in, that is, 100. the second parameter resultcode is generally a flag value manually set before activityb is destroyed, that is, the setting code in activityb: setresult (200); finish (); that is, set the value first, and then finish B. Then we will return the resultcode: 200 we set ourselves to. In this case, the onactivityresult () method in a can receive the two values at the same time.
why do we need to manually set resultcode in B? Because, if sometimes we need to click a button (or another operation) in B, we need to return to a, that is, we will call the finish method of, however, if the user directly presses the back key to remove afinish, then we do not know the way in which B is finished in a, so we set the result flag. In addition, some people also need to bring back some data to a while B finishes. For example, if B is currently logged on to the user interface, but what I want to implement is to return the user name to a after logging on to the user interface B successfully. As shown above, we must use another overload method of setresult (): setresult (INT
resultcoe, intent data ), that is, we can use the intent object to transmit data between two activities. That is, we can put our data in the intent, and finally use setresult (200, data) to simultaneously pass the flag 200 and our own user name data to.