salman khalid
salman khalid

Reputation: 4934

Definition of Android Bundle

I am new to Android. Can you tell me what is a Bundle and how they are used in android?

Upvotes: 16

Views: 11850

Answers (4)

Bill The Ape
Bill The Ape

Reputation: 3306

The Android developer reference overview states:

A mapping from String values to various Parcelable types.

IOW, a Bundle is a set of key/value pairs, where it implements an interface called Parcelable.

Unlike a C++ map, which is also a container of key/value pairs but all values are of the same type, a Bundle can contain values of different types.

Upvotes: 3

Uttam
Uttam

Reputation: 12399

Android using Bundle for sharing variables. Bundle is used to pass data between Activities. You can create a bundle, pass it to Intent that starts the activity which then can be used from the destination activity.

Here is Good Sample Example.

Upvotes: 3

Chirag
Chirag

Reputation: 56925

Bundle generally use for passing data between various Activities. It depends on you what type of values you want to pass but bundle can hold all types of values and pass to the new activity.

You can use it like ...

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

Now you can get the passed values by...

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

you can also find more info on android-using-bundle-for-sharing-variables and Passing-Bundles-Around-Activities

Copy from Here.

Upvotes: 14

nhaarman
nhaarman

Reputation: 100418

Read this:

http://developer.android.com/reference/android/os/Bundle.html

It can be used to pass data between different Activity's

Upvotes: 5

Related Questions