Search code examples
androidandroid-intentandroid-bundle

How to get extras without a key?


As is known to all, we can put the extra info into an Intent by using putExtra/putExtras, and pass it to another app. At the destination, we can use getxxxExtra/getExtras to get this information. However, all these methods request a key.

I was wondering if there is any way to obtain information without a key. Or, is there any way to check all the keys that have been set into the bundle?

Thanks in advance!


Solution

  • if there is any way to obtain information without a key.

    No, there is no way to send data without any key, You need to use some sort of key whether it's Intent.EXTRA or your defined key

    is there any way to check all the keys that have been set into the bundle?

    Yes, you can use getIntent().getExtras().keySet() this will give you a Set (of String) containing all keys.

    Bundle bundle = getIntent().getExtras();
    Set<String> bundleKeySet = bundle.keySet(); // string key set
    for(String key : bundleKeySet){ // traverse and print pairs
        Log.i(key," : " + bundle.get(key));
    }