Wrong requestCode returned onActivityResult from another Activity

前端 未结 2 1070
Happy的楠姐
Happy的楠姐 2021-02-18 14:04

I have an Activity that calls another Activity, that calls some other Activities. I send to the last Activity to get a result

2条回答
  •  别那么骄傲
    2021-02-18 14:34

    The request code is not random. 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 to. Reference.

    For example, 196614 is really 3 << 16 + 6 where 3 is the fragment index plus one and 6 is your request code.

    Morale: Don't mix activity/fragment startActivityForResult() and onActivityResult(). When started from an activity, process the result in the activity. When started from a fragment, process the result in the fragment.

提交回复
热议问题