What is the meaning of requestCode in startActivityForResult

后端 未结 4 1725
不知归路
不知归路 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:47

    Explanation is illustrated in picture.

     public void onActivityResult(int requestCode, int resultCode, Intent data)
    

    app receives results from the different intents via above method only. So how will you understand which intent had replied to you? For that reason, before invoking the intents we put a self defined TAG/Label which is called requestCode. By our own defined requestCODE we can check which intent's result we have received.

    Here in requestCode in the example I have given 1001 for Camera Intent. You can put any of your desired number. 1200 or 2001 or 21. Any Positive integers ranging to ~2^16.

    See the picture attached.

提交回复
热议问题