What is the meaning of requestCode in startActivityForResult

后端 未结 4 1723
不知归路
不知归路 2021-01-30 16:21

I\'m wondering if I am understanding the concepts of requestCode correectly. What is this integer for and does it matter what integer I set it to in:

         


        
4条回答
  •  执笔经年
    2021-01-30 16:31

    Using an integer out of the range will raise a "java.lang.IllegalArgumentException: Can only use lower 16 bits for requestCode" exception.

    So keep in mind that request is not just any positive integer but an integer of 16 bits, so from 0 to 65535.

    Similarly, validateRequestPermissionsRequestCode in FragmentActivity requires requestCode to be of 8 bits, so between 0 and 255.

提交回复
热议问题