FileDocCategorySizeDatePackage
Bundle.javaAPI DocAndroid 5.1 API32955Thu Mar 12 22:22:10 GMT 2015android.os

Bundle

public final class Bundle extends BaseBundle implements Cloneable, Parcelable
A mapping from String values to various Parcelable types.

Fields Summary
public static final Bundle
EMPTY
static final Parcel
EMPTY_PARCEL
private boolean
mHasFds
private boolean
mFdsKnown
private boolean
mAllowFds
public static final Parcelable.Creator
CREATOR
Constructors Summary
public Bundle()
Constructs a new, empty Bundle.


              
      
        super();
    
Bundle(Parcel parcelledData)
Constructs a Bundle whose data is stored as a Parcel. The data will be unparcelled on first contact, using the assigned ClassLoader.

param
parcelledData a Parcel containing a Bundle

        super(parcelledData);

        mHasFds = mParcelledData.hasFileDescriptors();
        mFdsKnown = true;
    
Bundle(Parcel parcelledData, int length)

        super(parcelledData, length);

        mHasFds = mParcelledData.hasFileDescriptors();
        mFdsKnown = true;
    
public Bundle(ClassLoader loader)
Constructs a new, empty Bundle that uses a specific ClassLoader for instantiating Parcelable and Serializable objects.

param
loader An explicit ClassLoader to use when instantiating objects inside of the Bundle.

        super(loader);
    
public Bundle(int capacity)
Constructs a new, empty Bundle sized to hold the given number of elements. The Bundle will grow as needed.

param
capacity the initial capacity of the Bundle

        super(capacity);
    
public Bundle(Bundle b)
Constructs a Bundle containing a copy of the mappings from the given Bundle.

param
b a Bundle to be copied.

        super(b);

        mHasFds = b.mHasFds;
        mFdsKnown = b.mFdsKnown;
    
public Bundle(PersistableBundle b)
Constructs a Bundle containing a copy of the mappings from the given PersistableBundle.

param
b a Bundle to be copied.

        super(b);
    
Methods Summary
public voidclear()
Removes all elements from the mapping of this Bundle.

        super.clear();

        mHasFds = false;
        mFdsKnown = true;
    
public java.lang.Objectclone()
Clones the current Bundle. The internal map is cloned, but the keys and values to which it refers are copied by reference.

        return new Bundle(this);
    
public intdescribeContents()
Report the nature of this Parcelable's contents


                
    
       
        int mask = 0;
        if (hasFileDescriptors()) {
            mask |= Parcelable.CONTENTS_FILE_DESCRIPTOR;
        }
        return mask;
    
public static android.os.BundleforPair(java.lang.String key, java.lang.String value)
Make a Bundle for a single key/value pair.

hide

        Bundle b = new Bundle(1);
        b.putString(key, value);
        return b;
    
public IBindergetBinder(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
an IBinder value, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (IBinder) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "IBinder", e);
            return null;
        }
    
public android.os.BundlegetBundle(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Bundle value, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (Bundle) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "Bundle", e);
            return null;
        }
    
public bytegetByte(java.lang.String key)
Returns the value associated with the given key, or (byte) 0 if no mapping of the desired type exists for the given key.

param
key a String
return
a byte value

        return super.getByte(key);
    
public java.lang.BytegetByte(java.lang.String key, byte defaultValue)
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

param
key a String
param
defaultValue Value to return if key does not exist
return
a byte value

        return super.getByte(key, defaultValue);
    
public byte[]getByteArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a byte[] value, or null

        return super.getByteArray(key);
    
public chargetChar(java.lang.String key)
Returns the value associated with the given key, or (char) 0 if no mapping of the desired type exists for the given key.

param
key a String
return
a char value

        return super.getChar(key);
    
public chargetChar(java.lang.String key, char defaultValue)
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

param
key a String
param
defaultValue Value to return if key does not exist
return
a char value

        return super.getChar(key, defaultValue);
    
public char[]getCharArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a char[] value, or null

        return super.getCharArray(key);
    
public java.lang.CharSequencegetCharSequence(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a CharSequence value, or null

        return super.getCharSequence(key);
    
public java.lang.CharSequencegetCharSequence(java.lang.String key, java.lang.CharSequence defaultValue)
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key or if a null value is explicitly associatd with the given key.

param
key a String, or null
param
defaultValue Value to return if key does not exist or if a null value is associated with the given key.
return
the CharSequence value associated with the given key, or defaultValue if no valid CharSequence object is currently mapped to that key.

        return super.getCharSequence(key, defaultValue);
    
public java.lang.CharSequence[]getCharSequenceArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a CharSequence[] value, or null

        return super.getCharSequenceArray(key);
    
public java.util.ArrayListgetCharSequenceArrayList(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
an ArrayList value, or null

        return super.getCharSequenceArrayList(key);
    
public java.lang.ClassLoadergetClassLoader()
Return the ClassLoader currently associated with this Bundle.

        return super.getClassLoader();
    
public floatgetFloat(java.lang.String key)
Returns the value associated with the given key, or 0.0f if no mapping of the desired type exists for the given key.

param
key a String
return
a float value

        return super.getFloat(key);
    
public floatgetFloat(java.lang.String key, float defaultValue)
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

param
key a String
param
defaultValue Value to return if key does not exist
return
a float value

        return super.getFloat(key, defaultValue);
    
public float[]getFloatArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a float[] value, or null

        return super.getFloatArray(key);
    
public IBindergetIBinder(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
an IBinder value, or null
deprecated
hide
This is the old name of the function.

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (IBinder) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "IBinder", e);
            return null;
        }
    
public java.util.ArrayListgetIntegerArrayList(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
an ArrayList value, or null

        return super.getIntegerArrayList(key);
    
public TgetParcelable(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Parcelable value, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (T) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "Parcelable", e);
            return null;
        }
    
public Parcelable[]getParcelableArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Parcelable[] value, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (Parcelable[]) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "Parcelable[]", e);
            return null;
        }
    
public java.util.ArrayListgetParcelableArrayList(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
an ArrayList value, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (ArrayList<T>) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "ArrayList", e);
            return null;
        }
    
public java.io.SerializablegetSerializable(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Serializable value, or null

        return super.getSerializable(key);
    
public shortgetShort(java.lang.String key)
Returns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key.

param
key a String
return
a short value

        return super.getShort(key);
    
public shortgetShort(java.lang.String key, short defaultValue)
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

param
key a String
param
defaultValue Value to return if key does not exist
return
a short value

        return super.getShort(key, defaultValue);
    
public short[]getShortArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a short[] value, or null

        return super.getShortArray(key);
    
public android.util.SizegetSize(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Size value, or null

        unparcel();
        final Object o = mMap.get(key);
        try {
            return (Size) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "Size", e);
            return null;
        }
    
public android.util.SizeFgetSizeF(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a Size value, or null

        unparcel();
        final Object o = mMap.get(key);
        try {
            return (SizeF) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "SizeF", e);
            return null;
        }
    
public android.util.SparseArraygetSparseParcelableArray(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
a SparseArray of T values, or null

        unparcel();
        Object o = mMap.get(key);
        if (o == null) {
            return null;
        }
        try {
            return (SparseArray<T>) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "SparseArray", e);
            return null;
        }
    
public java.util.ArrayListgetStringArrayList(java.lang.String key)
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

param
key a String, or null
return
an ArrayList value, or null

        return super.getStringArrayList(key);
    
public booleanhasFileDescriptors()
Reports whether the bundle contains any parcelled file descriptors.

        if (!mFdsKnown) {
            boolean fdFound = false;    // keep going until we find one or run out of data

            if (mParcelledData != null) {
                if (mParcelledData.hasFileDescriptors()) {
                    fdFound = true;
                }
            } else {
                // It's been unparcelled, so we need to walk the map
                for (int i=mMap.size()-1; i>=0; i--) {
                    Object obj = mMap.valueAt(i);
                    if (obj instanceof Parcelable) {
                        if ((((Parcelable)obj).describeContents()
                                & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
                            fdFound = true;
                            break;
                        }
                    } else if (obj instanceof Parcelable[]) {
                        Parcelable[] array = (Parcelable[]) obj;
                        for (int n = array.length - 1; n >= 0; n--) {
                            if ((array[n].describeContents()
                                    & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
                                fdFound = true;
                                break;
                            }
                        }
                    } else if (obj instanceof SparseArray) {
                        SparseArray<? extends Parcelable> array =
                                (SparseArray<? extends Parcelable>) obj;
                        for (int n = array.size() - 1; n >= 0; n--) {
                            if ((array.valueAt(n).describeContents()
                                    & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0) {
                                fdFound = true;
                                break;
                            }
                        }
                    } else if (obj instanceof ArrayList) {
                        ArrayList array = (ArrayList) obj;
                        // an ArrayList here might contain either Strings or
                        // Parcelables; only look inside for Parcelables
                        if (!array.isEmpty() && (array.get(0) instanceof Parcelable)) {
                            for (int n = array.size() - 1; n >= 0; n--) {
                                Parcelable p = (Parcelable) array.get(n);
                                if (p != null && ((p.describeContents()
                                        & Parcelable.CONTENTS_FILE_DESCRIPTOR) != 0)) {
                                    fdFound = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            mHasFds = fdFound;
            mFdsKnown = true;
        }
        return mHasFds;
    
public voidputAll(android.os.Bundle bundle)
Inserts all mappings from the given Bundle into this Bundle.

param
bundle a Bundle

        unparcel();
        bundle.unparcel();
        mMap.putAll(bundle.mMap);

        // fd state is now known if and only if both bundles already knew
        mHasFds |= bundle.mHasFds;
        mFdsKnown = mFdsKnown && bundle.mFdsKnown;
    
public voidputBinder(java.lang.String key, IBinder value)
Inserts an {@link IBinder} value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

You should be very careful when using this function. In many places where Bundles are used (such as inside of Intent objects), the Bundle can live longer inside of another process than the process that had originally created it. In that case, the IBinder you supply here will become invalid when your process goes away, and no longer usable, even if a new process is created for you later on.

param
key a String, or null
param
value an IBinder object, or null

        unparcel();
        mMap.put(key, value);
    
public voidputBundle(java.lang.String key, android.os.Bundle value)
Inserts a Bundle value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a Bundle object, or null

        unparcel();
        mMap.put(key, value);
    
public voidputByte(java.lang.String key, byte value)
Inserts a byte value into the mapping of this Bundle, replacing any existing value for the given key.

param
key a String, or null
param
value a byte

        super.putByte(key, value);
    
public voidputByteArray(java.lang.String key, byte[] value)
Inserts a byte array value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a byte array object, or null

        super.putByteArray(key, value);
    
public voidputChar(java.lang.String key, char value)
Inserts a char value into the mapping of this Bundle, replacing any existing value for the given key.

param
key a String, or null
param
value a char, or null

        super.putChar(key, value);
    
public voidputCharArray(java.lang.String key, char[] value)
Inserts a char array value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a char array object, or null

        super.putCharArray(key, value);
    
public voidputCharSequence(java.lang.String key, java.lang.CharSequence value)
Inserts a CharSequence value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a CharSequence, or null

        super.putCharSequence(key, value);
    
public voidputCharSequenceArray(java.lang.String key, java.lang.CharSequence[] value)
Inserts a CharSequence array value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a CharSequence array object, or null

        super.putCharSequenceArray(key, value);
    
public voidputCharSequenceArrayList(java.lang.String key, java.util.ArrayList value)
Inserts an ArrayList value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value an ArrayList object, or null

        super.putCharSequenceArrayList(key, value);
    
public voidputFloat(java.lang.String key, float value)
Inserts a float value into the mapping of this Bundle, replacing any existing value for the given key.

param
key a String, or null
param
value a float

        super.putFloat(key, value);
    
public voidputFloatArray(java.lang.String key, float[] value)
Inserts a float array value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a float array object, or null

        super.putFloatArray(key, value);
    
public voidputIBinder(java.lang.String key, IBinder value)
Inserts an IBinder value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value an IBinder object, or null
deprecated
hide
This is the old name of the function.

        unparcel();
        mMap.put(key, value);
    
public voidputIntegerArrayList(java.lang.String key, java.util.ArrayList value)
Inserts an ArrayList value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value an ArrayList object, or null

        super.putIntegerArrayList(key, value);
    
public voidputParcelable(java.lang.String key, Parcelable value)
Inserts a Parcelable value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a Parcelable object, or null

        unparcel();
        mMap.put(key, value);
        mFdsKnown = false;
    
public voidputParcelableArray(java.lang.String key, Parcelable[] value)
Inserts an array of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value an array of Parcelable objects, or null

        unparcel();
        mMap.put(key, value);
        mFdsKnown = false;
    
public voidputParcelableArrayList(java.lang.String key, java.util.ArrayList value)
Inserts a List of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value an ArrayList of Parcelable objects, or null

        unparcel();
        mMap.put(key, value);
        mFdsKnown = false;
    
public voidputParcelableList(java.lang.String key, java.util.List value)
{@hide}

        unparcel();
        mMap.put(key, value);
        mFdsKnown = false;
    
public voidputSerializable(java.lang.String key, java.io.Serializable value)
Inserts a Serializable value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a Serializable object, or null

        super.putSerializable(key, value);
    
public voidputShort(java.lang.String key, short value)
Inserts a short value into the mapping of this Bundle, replacing any existing value for the given key.

param
key a String, or null
param
value a short

        super.putShort(key, value);
    
public voidputShortArray(java.lang.String key, short[] value)
Inserts a short array value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a short array object, or null

        super.putShortArray(key, value);
    
public voidputSize(java.lang.String key, android.util.Size value)
Inserts a Size value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a Size object, or null

        unparcel();
        mMap.put(key, value);
    
public voidputSizeF(java.lang.String key, android.util.SizeF value)
Inserts a SizeF value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a SizeF object, or null

        unparcel();
        mMap.put(key, value);
    
public voidputSparseParcelableArray(java.lang.String key, android.util.SparseArray value)
Inserts a SparceArray of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value a SparseArray of Parcelable objects, or null

        unparcel();
        mMap.put(key, value);
        mFdsKnown = false;
    
public voidputStringArrayList(java.lang.String key, java.util.ArrayList value)
Inserts an ArrayList value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.

param
key a String, or null
param
value an ArrayList object, or null

        super.putStringArrayList(key, value);
    
public voidreadFromParcel(Parcel parcel)
Reads the Parcel contents into this Bundle, typically in order for it to be passed through an IBinder connection.

param
parcel The parcel to overwrite this bundle from.

        super.readFromParcelInner(parcel);
        mHasFds = mParcelledData.hasFileDescriptors();
        mFdsKnown = true;
    
public booleansetAllowFds(boolean allowFds)

hide

        boolean orig = mAllowFds;
        mAllowFds = allowFds;
        return orig;
    
public voidsetClassLoader(java.lang.ClassLoader loader)
Changes the ClassLoader this Bundle uses when instantiating objects.

param
loader An explicit ClassLoader to use when instantiating objects inside of the Bundle.

        super.setClassLoader(loader);
    
public synchronized java.lang.StringtoString()

        if (mParcelledData != null) {
            if (mParcelledData == EMPTY_PARCEL) {
                return "Bundle[EMPTY_PARCEL]";
            } else {
                return "Bundle[mParcelledData.dataSize=" +
                        mParcelledData.dataSize() + "]";
            }
        }
        return "Bundle[" + mMap.toString() + "]";
    
public voidwriteToParcel(Parcel parcel, int flags)
Writes the Bundle contents to a Parcel, typically in order for it to be passed through an IBinder connection.

param
parcel The parcel to copy this bundle to.

        final boolean oldAllowFds = parcel.pushAllowFds(mAllowFds);
        try {
            super.writeToParcelInner(parcel, flags);
        } finally {
            parcel.restoreAllowFds(oldAllowFds);
        }