识别多个意图(对于 onActivityResult) [英] Recognizing multiple intents (for onActivityResult)

查看:40
本文介绍了识别多个意图(对于 onActivityResult)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一项活动中有 5 个意图.他们都在使用 startActivityForResult.因为它们都是为了对应布局中的不同元素.我如何识别哪个意图是结果.

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.

例如如果我有 intent1、intent2、intent3,它们都在使用 startActivityForResult.Intent 业务完成后.我现在如何在我的 onActivityResult 中识别调用了哪个意图.被调用的意图是安卓手机联系人意图.

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.

推荐答案

当你调用 startActivityForResult() 时,你设置了 requestCode.稍后,您可以在onActivityResult() 中使用此请求代码来确定意图.有关更多信息,请参阅什么是来自 onActivityResult 参数的 Intent.如果您看到 onActivityResult,它提到:

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:最初提供给 startActivityForResult() 的整数请求代码,允许您识别此结果来自谁.

这篇关于识别多个意图(对于 onActivityResult)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆