onActivityResult is not being called in Fragment

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

    I was also facing the same problem once I shifted this block of code outside of a Fragment to a Utility Class, with parentActivity passed as argument,

    Intent intent = new Intent(parentActivity, CameraCaptureActivity.class);
    parentActivity.startActivityForResult(intent,requestCode);
    

    Then I was not getting any value in onActivityResult method of that Fragment, Afterwards, I changed the argument to Fragment, so the revised definition of method looked like,

    Intent intent = new Intent(fragment.getContext(), CameraCaptureActivity.class);
    fragment.startActivityForResult(intent,requestCode);
    

    After that, I was able to get value in onActivityResult on the Fragment

提交回复
热议问题