Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent and Bundle Relation

While using Intent object we can put different types of data directly using its putExtra(). We can also put these extra data into a Bundle object and add it to Intent. So why do we need Bundle if we can do so using Intent directly?

like image 751
Android Killer Avatar asked Sep 24 '11 08:09

Android Killer


2 Answers

As you can see, the Intent internally stores it in a Bundle.

public Intent putExtra(String name, String value) {
    if (mExtras == null) {
        mExtras = new Bundle();
    }
    mExtras.putString(name, value);
    return this;
}
like image 152
Reno Avatar answered Oct 27 '22 06:10

Reno


Sometimes you need to pass only a few variables or values to some Other Activity, but what if you have a bunch of variable's or values that you need to pass to various Activities. In that case you can use Bundle and pass the Bundle to the required Activity with ease. Instead of passing single variable's every time.

like image 36
Lalit Poptani Avatar answered Oct 27 '22 06:10

Lalit Poptani