Wrong requestCode in onActivityResult

前端 未结 6 1119
离开以前
离开以前 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:37

    The request code is not wrong. When using v4 support library fragments, fragment index is encoded in the top 16 bits of the request code and your request code is in the bottom 16 bits. The fragment index is later used to find the correct fragment to deliver the result.

    Hence for Activities started form fragment object, handle onActivityResult requestCode like below:

    originalRequestCode = changedRequestCode - (indexOfFragment << 16)
          6             =      196614        -       (3 << 16)
    

提交回复
热议问题