What is a "bundle" in an Android application

User picture User · Feb 15, 2011 · Viewed 259.2k times · Source

What is a bundle in an Android application? When to use it?

Answer

samtherock picture samtherock · Feb 15, 2011

Bundles are generally used for passing data between various Android activities. It depends on you what type of values you want to pass, but bundles can hold all types of values and pass them to the new activity.

You can use it like this:

Intent intent = new...
Intent(getApplicationContext(), SecondActivity.class);
intent.putExtra("myKey", AnyValue);  
startActivity(intent);

You can get the passed values by doing:

Bundle extras = intent.getExtras(); 
String tmp = extras.getString("myKey");

You can find more info at: