A popup acitivity is used in the project to get user input, so the Onactivityresult () method is used to accept user input.
Strange question Startactivityforresult () after calling Onactivityresult () directly
Developers know that parameters can be passed or received by using the Startactivityforresult () and Onactivityresult () methods.
However, in the project, Onactivityresult () was executed without waiting for the called Activity to return.
Looking for a long time, finally through the grapevine, this is related to the Activity loading mode (Launchmode), the property can be set in Androidmanifest.xml.
<activity android:name= "savefileactivity" android:launchmode= "Singletask" android: Theme= "@style/savefile"/>
Originally set to singleinstance, tested, all the Activity that needs to be passed or received is not allowed to set this property, or can be set to standard mode, otherwise the system will call directly after Startactivityforresult () Onactivityresult (). Remove the singletask from the XML above.
Onactivityresult unresponsive issue after calling Startactivityforresult
When two activity passes data and returns data, the requester's onactivityresult is always unresponsive, and the method is not invoked through debug debug mode. The various configuration and program codes were reviewed and no errors were found. After looking for a lot of information, finally see a friend said is called Startactivityforresult parameter problem, that is called when this:
Startactivityforresult (Intent, 0);
Is the problem with the second argument, the parameter must be greater than 0 to return the value, and the Onactivityresult method is activated.
I started with an activity. The default constant: RESULT_OK, after tracking the code, found that the value of the constant is-1, of course, can not activate the Onactivityresult method, and then arbitrarily modified to a greater than 0 integer, the program is the success of the run.
Startactivityforresult (Intent, 1); That's it, okay?
Android Basics: Startactivityforresult and Onactivityresult issues