onActivityResult is not being called in Fragment

后端 未结 30 2697
忘了有多久
忘了有多久 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:14

    For those who use Android Navigation Component should use in Activity's onActivityResult(...) the primaryNavigationFragment to get it's fragment reference and call fragment's fragment.onActivityResult(...).

    Here's Activity's onActivityResult(...)

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent imageData)
    {
        super.onActivityResult(requestCode, resultCode, imageData);
    
        for (Fragment fragment : getSupportFragmentManager().getPrimaryNavigationFragment().getChildFragmentManager().getFragments())
        {
                fragment.onActivityResult(requestCode, resultCode, imageData);
        }
    }
    

提交回复
热议问题