Android Basics: Startactivityforresult and Onactivityresult issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.