简体   繁体   中英

return to Activity's onActivityResult from fragment's child

ActivityCat starts DialogFragmentLoves with show() . Then DialogFramentLoves starts ActivityDog with startActivityForResult . When ActivityDog returns, naturally it calls the onActivityResult method that is inside the Fragment. But I want the data to go to ActivityCat. But doing as follows inside DialogFragmentLoves does not work:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    getActivity().onActivityResult(requestCode, resultCode, data);
    dismiss();
}

What's the correct way of doing this?

Actually the documentation of startActivityForResult in Fragment says

Call startActivityForResult(Intent, int) from the fragment's containing Activity.

So actually it should work as it is now. Maybe it's enough to not override onActivityResult in your fragment? Or maybe you're not calling super.onActivityResult()? Another option might be to call getActivity().startActivityForResult instead...although this should be exactly what the fragment's method seems to do...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM