List or print all extras from intent or bundle

×

Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in bootstrap_table() (line 114 of /home/porquefu/public_html/android-snippets.com/sites/all/themes/bootstrap/templates/system/table.func.php).
  • Warning: count(): Parameter must be an array or an object that implements Countable in bootstrap_table() (line 189 of /home/porquefu/public_html/android-snippets.com/sites/all/themes/bootstrap/templates/system/table.func.php).
  • Warning: count(): Parameter must be an array or an object that implements Countable in bootstrap_table() (line 238 of /home/porquefu/public_html/android-snippets.com/sites/all/themes/bootstrap/templates/system/table.func.php).
  • Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in menu_set_active_trail() (line 2405 of /home/porquefu/public_html/android-snippets.com/includes/menu.inc).
+1
-60
-1

List or print all "Extras" from intent or Bundle

This snippet is for listing all "Extras" from intent or any data stored in a bundle

Android class Bundle is a widely used class for passing data between several activities.

In many times, yo are faced to a bundle and you don't know what information it contains, so listing all the key-value pairs inside the content of the bundle could be really handy

Here is the android code you can use to list the data contained in the bundle. enjoy it and make any comment

XML code: 
JAVA code: 
StringBuilder builder = new StringBuilder("Extras:\n");
for (String key : extras.keySet()) { //extras is the Bundle containing info 
	Object value = extras.get(key); //get the current object
	builder.append(key).append(": ").append(value).append("\n"); //add the key-value pair to the 
}
Log.i("Extras",builder.toString()); //log the data or use it as needed.