onActivityResult is not being called in Fragment

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

    Inside your fragment, call

    this.startActivityForResult(intent, REQUEST_CODE);
    

    where this is referring to the fragment. Otherwise do as @Clevester said:

    Fragment fragment = this;
    ....
    fragment.startActivityForResult(intent, REQUEST_CODE);
    

    I also had to call

    super.onActivityResult(requestCode, resultCode, data);
    

    in the parent activity's onActivityResult to make it work.

    (I adapted this answer from @Clevester's answer.)

提交回复
热议问题