Android Bundle

A Bundle is a data structure that provides mapping from String values to Parceable types.

Bundle class definition

Bundle belongs to android.os package.

package android.os;

Bundle is a final class so you cannot derive from it:

public final class Bundle...{}

It derives from a android.os.BaseBundle class:

public final class Bundle extends BaseBundle..{}

Bundle implements two interfaces:

Interface Description
Cloneable So that it supports cloning.
Parcelable So that it supports writing to and restoration from a parcel.

Creating a Bundle

A Bundle is like all Java classes is an Object. Objects do have constructors.

A constructor is a method that gets called when the object is created. When an object is instantiated. Basically the constructors create or construct objects.

Well the Bundle class has 5 of these constructors that we can use to create a Bundle object. They only differ in the parameters we pass to the object.

Constructor Description
Bundle() This will create a new empty Bundle object
Bundle(int capacity) Create a new Bundle object with the total capacity specified in the parameter.
Bundle(Bundle b) Creates a bundle object with a copy of entries from the passed Bundle.
Bundle(PersitableBundle b) This will create a Bundle with a copy of entires from the passed PersistableBundle.

Top Android Bundle Examples

Let's look at some examples.

When developing any application which isn't a Hello World, then chances are that you will need to have more than one Activity or Fragments.Fragments basically are subactivities.

Most newbies get confused with passing data between activities or between fragments.

Today we want to see how to pass data from an activity to a fragment. We'll use a Bundle object, pack data to it in our Activity, then unpack that data inside the onCreateView() method of our Fragment.

Best Regards, Oclemy.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:


What do You Think

Previous Post Next Post