onActivityResult() not called when Activity started from Fragment

前端 未结 3 1566
北恋
北恋 2020-12-05 09:49

I have an issue with importing a picture from the Album in Android, because the onActivityResult() method is never called.

This is the code that I wrote

3条回答
  •  广开言路
    2020-12-05 10:30

    To have onActivityResult() called in the fragment, you should call the fragment's version of startActivityForResult(), not the activity's. So in your fragment's code, replace

    getActivity().startActivityForResult(galleryIntent, PICK_IMAGE);
    

    with

    startActivityForResult(galleryIntent, PICK_IMAGE);
    

提交回复
热议问题