我如何知道捆绑包中提供了哪些数据?

问题描述

| 我花了一点时间来确定通过
Intent
/
Bundle
s哪些数据正在到达我的方法。我曾尝试添加断点来检查数据,但没有任何显示。也许因为它是2英镑,所以我无法在Eclipse中手动读取它。 例如,a3ѭ代表
Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI)
。我如何知道可用的数据?请注意,我不是在要求提供什么数据,而是怎么弄清楚,以便可以将相同的思想应用于Android框架中的任何
Bundle
/
Intent
?也许看文档很简单,但是我看不到数据的完整列表,而且在Eclipse中也看不到它。所以我迷路了。     

解决方法

        
Bundle.keySet()
为您提供捆绑中所有钥匙的清单。也就是说,通常您只期望某些键并查询它们,但是
keySet()
用来检查从某处获得的捆绑包。     ,        
public static String bundle2string(Bundle bundle) {
    if (bundle == null) {
        return null;
    }
    String string = \"Bundle{\";
    for (String key : bundle.keySet()) {
        string += \" \" + key + \" => \" + bundle.get(key) + \";\";
    }
    string += \" }Bundle\";
    return string;
}
    ,        我得到存储的捆绑包的alll键和值...
for (String key : bundle.keySet()) {
    string += \" \" + key + \" => \" + bundle.get(key) + \";\";
}
输出:
(key)       :(value)    
profile_name:abc
    ,        您从捆绑软件中获得的唯一东西就是您放入的东西。捆绑软件是在活动之间传递信息的方式。如果您负责整个应用程序,则无需在Bundle中查看对象,只需抓住它们即可。考虑一下哈希图键...如果您不知道该键,那不是您可以搜索该哈希图。 要将项目放入捆绑包并将其传递到下一个活动,您需要将其作为附加项目放置。在这里看看通过活动之间的附加和捆绑传递数据的示例。 复制并粘贴在下面: 从活动1
Intent intent = new Intent(this,myActivity2.class);
Bundle bundle = new Bundle();
bundle.putString(\"myValue\",myValue);
intent.putExtras(bundle);
navigation.this.startActivity(intent);
活动2
Bundle bundle = getIntent().getExtras();
act2MyValue= bundle.getString(\"myValue\");
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...