Wrong requestCode in onActivityResult

前端 未结 6 1123
离开以前
离开以前 2020-11-28 01:14

I\'m starting a new Activity from my Fragment with

startActivityForResult(intent, 1);

and want to handle the result in the Fragment\'s pare

6条回答
  •  鱼传尺愫
    2020-11-28 01:58

    You are calling startActivityForResult() from your Fragment. When you do this, the requestCode is changed by the Activity that owns the Fragment.

    If you want to get the correct resultCode in your activity try this:

    Change:

    startActivityForResult(intent, 1);
    

    To:

    getActivity().startActivityForResult(intent, 1);
    

提交回复
热议问题