Android uses startActivityForResult in ActivityGroup

Source: Internet
Author: User

Suppose there is an ActivityGroup A, which contains two sub-activities B and C, jump to another Activity D in C, and then execute some operations in D, refresh the D interface when you finish and return D again. How can this problem be achieved?
In C, c. startActivityForResult (D, 0), and setResult (1) Before D finish (). Therefore, the onActivityResult in C cannot receive the return code 1 returned from D, the interface cannot be refreshed.

Solution:
C start D:
[Java]
Intent intent = new Intent (C. this, D. class );
GetParent (). startActivityForResult (intent, 0 );

Then rewrite onActivityResult in:
[Java]
Protected void onActivityResult (int requestCode, int resultCode, Intent data ){
// TODO Auto-generated method stub
Super. onActivityResult (requestCode, resultCode, data );
If (requestCode = 0 ){
C activity = (C) getLocalActivityManager (). getCurrentActivity ();
Activity. handleActivityResult (requestCode, resultCode, data); // send the received message to Activity C that initiates the request
}
}

Finally, add the handleActivityResult method to C.
[Java]
Public void handleActivityResult (int requestCode, int resultCode, Intent data ){
If (resultCode = 1) {// get the return code and refresh the interface
Log. I (TAG, "Return Code:" + resultCode );
}
}

Related Article

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.