我怎么知道Bundle中给出的数据?

use*_*321 42 android bundle android-intent

我有一点时间通过Intent/ Bundles 搞清楚我的方法会有什么数据.我已经尝试添加断点来检查数据,但我没有看到任何东西.也许是因为Parcelable我无法在Eclipse中手动读取它.

例如,a onActivityResult(int requestCode, int resultCode, Intent data)表示a Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI).我如何知道可用的数据?请注意,我不是要求提供哪些数据,但我是如何理解的,所以我可以将相同的想法应用于任何Bundle/ Intent来自Android框架?也许这看起来像文档一样简单,但我没有看到完整的数据列表,我在Eclipse中看不到它.所以我迷路了.

Ebo*_*ike 79

Bundle.keySet()为您提供捆绑中所有密钥的列表.也就是说,通常你只是期望某些键并查询它们,但是keySet()用于检查从某个地方获得的包.


184*_*615 47

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;
}
Run Code Online (Sandbox Code Playgroud)

  • 像你这样的伙伴是我如此积极地为我们提供现成咖啡的原因:P谢谢 (7认同)

Pan*_*iya 6

我得到了存储包的所有键和值...

for (String key : bundle.keySet()) {
    string += " " + key + " => " + bundle.get(key) + ";";
}
Run Code Online (Sandbox Code Playgroud)

输出:

(key)       :(value)    
profile_name:abc
Run Code Online (Sandbox Code Playgroud)