Fragment's onActivityResult not called after orientation change

后端 未结 2 1004
庸人自扰
庸人自扰 2021-02-08 08:11

Please note, this question is not a duplicate of the following:

  • https://stackoverflow.com/questions/19006776/onactivityresult-not-working-with-fragments
  • o
2条回答
  •  迷失自我
    2021-02-08 08:41

    Resolved it by moving all of the onActivityResult logic from the Fragment to the Activity.

    Do note, however, that the reqCode that gets passed to the Fragment is different than the reqCode that gets delivered to the parent Activity (the one for the Activity is set by the system I think). This meant that I had to also move the original startActivityForResult call from the Fragment to the Activity, and then create a method to call it from the Fragment when needed.

    If anyone finds a more elegant way, I would be happy to hear about it.

提交回复
热议问题