Http://www.eifr.com/article.php? Id = 1464
Startactivityforresult () directly calls onactivityresult ()
Developers know that you can use startactivityforresult () and onactivityresult () Methods to pass or receive parameters.
However, in the listener project, onactivityresult () is executed before the called activity returns.
After searching for a long time, I finally learned through the gossip that this is related to the launchmode of the activity. This attribute can be set in androidmanifest. xml.
Originally set it to singleinstance. After testing, all the activities that need to be passed or received cannot set this attribute, or they can only be set to standard mode. Otherwise, the system will set this attribute in startactivityforresult () directly call onactivityresult ().
Onactivityresult does not respond after startactivityforresult is called.
When two activities pass data and return data, the onactivityresult of the requester never responds. This method is not called in debug mode. I checked various configurations and program code and found no errors. After looking for a lot of information, I finally saw a friend saying that it was a problem to call the startactivityforresult parameter, that is, the call was like this:
Startactivityforresult (intent, 0 );
Is a problem with the second parameter. This parameter must be greater than 0 to be returned, and the onactivityresult method is activated.
At first, I used the default constant result_ OK of an activity. After tracking the code, I found that the value of this constant is-1. Of course, the onactivityresult method cannot be activated, then, modify it to an integer greater than 0, and the program runs successfully.
Startactivityforresult (intent, 1 ); //.
1. startactivityforresult (intent, int
Requestcode );
2. setresut (int
Resultcode, intent );
3. onactivityresult (int
Requestcode, int resultcode, intent );
Note:
1. startactivityforresult was recently used. An error occurred. After tracking, the activity was not started, but onactivityresult was directly executed. View the log and find
05-19 02:11:19. 822: Warn/activitymanager (67): activity is launching as a new task, so
Canceling activity result ."
I set the launchmode of the activity to be started to singletask.
Correct the launchmode of the target activity.
Conclusion: The launchmode of the target activity cannot be set to singletask.
2. The requestcode value is greater than or equal to 0. Otherwise, startactivityforresult is changed to startactivity.