如何确定一个额外的由意向举行了包的类型? [英] How to determine the type of an extra in a bundle held by intent?

查看:109
本文介绍了如何确定一个额外的由意向举行了包的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想任意数据传递给的BroadcastReceiver 通过意图

I am trying to pass arbitrary data to a BroadcastReceiver through its Intent.

所以,我可能会做一些类似以下

So I might do something like the following

intent.putExtra("Some boolean", false);
intent.putExtra("Some char", 'a');
intent.putExtra("Some String", "But don't know what it will be");
intent.putExtra("Some long", 15134234124125);

然后把它传递给的BroadcastReceiver

我想通过来迭代Intent.getExtras()的东西,如键设置(),但我也希望能够拿到钥匙的价值,而不必硬code调用像方法.getStringExtra()。 getBooleanExtra()

I want to iterate through Intent.getExtras() with something like keySet(), but I would also like to be able to get the value of the key without having to hard-code calls to methods like .getStringExtra(), or .getBooleanExtra().

人如何做到这一点?

推荐答案

您可以使用下面的code得到来自任何时候一个对象意图

You can use the following code to get an object of any time from the Intent:

Bundle bundle = intent.getExtras();
Object value = bundle.get("key");

然后你就可以判断的使用对象实型的方法。

Then you can determine value's real type using Object's methods.

这篇关于如何确定一个额外的由意向举行了包的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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