Android Bundle

| Page Views: 314

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.

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.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post