onActivityResult is not being called in Fragment

后端 未结 30 2627
忘了有多久
忘了有多久 2020-11-21 04:28

The activity hosting this fragment has its onActivityResult called when the camera activity returns.

My fragment starts an activity for a result with th

30条回答
  •  别那么骄傲
    2020-11-21 05:07

    In my case it was an Android bug (http://technet.weblineindia.com/mobile/onactivityresult-not-getting-called-in-nested-fragments-android/), if you use supported FragmentActivity you have to use getSupportFragmentManager instead of getChildFragmentManager:

    List fragments = getSupportFragmentManager().getFragments();
    if (fragments != null) {
        for (Fragment fragment : fragments) {
            if(fragment instanceof UserProfileFragment) {
                fragment.onActivityResult(requestCode, resultCode, data);
            }
        }
    }
    

提交回复
热议问题