Android Bundle Introduction

February 11, 2018 Oclemy Android Bundle 1 minute, 3 seconds

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. A