Recognizing multiple intents (for onActivityResult

2019-07-13 23:43发布

I have 5 intents in one activity. All of them are using the startActivityForResult. Because all of them are to correspond to different elements in the layout. How do I recognize which intent is the result for.

For e.g. If I have intent1, intent2, intent3 all of which are using startActivityForResult. After the Intent business is done. How do I now in my onActivityResult recognize which intent was called. The intent being called upon is the android phone contacts intent.

1条回答
放荡不羁爱自由
2楼-- · 2019-07-14 00:03

When you call startActivityForResult(), you set the requestCode. Later, you can use this request code inonActivityResult() to determine the intent. see What is Intent from onActivityResult Parameters for more. If you see the documentation of onActivityResult, it mentions:

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

requestCode: The integer request code originally supplied to startActivityForResult(), allowing you to identify who this result came from.

查看更多
登录 后发表回答