Package android.os
Class Bundle
- java.lang.Object
-
- android.os.BaseBundle
-
- android.os.Bundle
-
- All Implemented Interfaces:
Parcelable,Cloneable
public final class Bundle extends BaseBundle implements Cloneable, Parcelable
A mapping from String values to various Parcelable types.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
-
-
Field Summary
Fields Modifier and Type Field Description static Parcelable.Creator<Bundle>CREATORReturns 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.static BundleEMPTY-
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
-
-
Constructor Summary
Constructors Constructor Description Bundle()Constructs a new, empty Bundle.Bundle(int capacity)Constructs a new, empty Bundle sized to hold the given number of elements.Bundle(Bundle b)Constructs a Bundle containing a copy of the mappings from the given Bundle.Bundle(PersistableBundle b)Constructs a Bundle containing a copy of the mappings from the given PersistableBundle.Bundle(ClassLoader loader)Constructs a new, empty Bundle that uses a specific ClassLoader for instantiating Parcelable and Serializable objects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Removes all elements from the mapping of this Bundle.Objectclone()Clones the current Bundle.intdescribeContents()Report the nature of this Parcelable's contentsvoidfilterValues()Filter values in Bundle to only basic types.static BundleforPair(String key, String value)Make a Bundle for a single key/value pair.boolean[]getBooleanArray(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.BundlegetBundle(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.bytegetByte(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.BytegetByte(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.byte[]getByteArray(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.chargetChar(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.chargetChar(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.char[]getCharArray(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.CharSequencegetCharSequence(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.CharSequencegetCharSequence(String key, 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.CharSequence[]getCharSequenceArray(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.ArrayList<CharSequence>getCharSequenceArrayList(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.ClassLoadergetClassLoader()Return the ClassLoader currently associated with this Bundle.floatgetFloat(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.floatgetFloat(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.float[]getFloatArray(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.ArrayList<Integer>getIntegerArrayList(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.<T extends Parcelable>
TgetParcelable(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.Parcelable[]getParcelableArray(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.<T extends Parcelable>
ArrayList<T>getParcelableArrayList(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.SerializablegetSerializable(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.shortgetShort(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.shortgetShort(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.short[]getShortArray(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.SizegetSize(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.SizeFgetSizeF(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.<T extends Parcelable>
SparseArray<T>getSparseParcelableArray(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.ArrayList<String>getStringArrayList(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.voidputAll(Bundle bundle)Inserts all mappings from the given Bundle into this Bundle.voidputBundle(String key, Bundle value)Inserts a Bundle value into the mapping of this Bundle, replacing any existing value for the given key.voidputByte(String key, byte value)Inserts a byte value into the mapping of this Bundle, replacing any existing value for the given key.voidputByteArray(String key, byte[] value)Inserts a byte array value into the mapping of this Bundle, replacing any existing value for the given key.voidputChar(String key, char value)Inserts a char value into the mapping of this Bundle, replacing any existing value for the given key.voidputCharArray(String key, char[] value)Inserts a char array value into the mapping of this Bundle, replacing any existing value for the given key.voidputCharSequence(String key, CharSequence value)Inserts a CharSequence value into the mapping of this Bundle, replacing any existing value for the given key.voidputCharSequenceArray(String key, CharSequence[] value)Inserts a CharSequence array value into the mapping of this Bundle, replacing any existing value for the given key.voidputCharSequenceArrayList(String key, ArrayList<CharSequence> value)Inserts an ArrayListvalue into the mapping of this Bundle, replacing any existing value for the given key. voidputFloat(String key, float value)Inserts a float value into the mapping of this Bundle, replacing any existing value for the given key.voidputFloatArray(String key, float[] value)Inserts a float array value into the mapping of this Bundle, replacing any existing value for the given key.voidputIBinder(String key, IBinder value)Deprecated.voidputIntegerArrayList(String key, ArrayList<Integer> value)Inserts an ArrayListvalue into the mapping of this Bundle, replacing any existing value for the given key. voidputParcelable(String key, Parcelable value)Inserts a Parcelable value into the mapping of this Bundle, replacing any existing value for the given key.voidputParcelableArray(String key, Parcelable[] value)Inserts an array of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.voidputParcelableArrayList(String key, ArrayList<? extends Parcelable> value)Inserts a List of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.voidputParcelableList(String key, List<? extends Parcelable> value)voidputSerializable(String key, Serializable value)Inserts a Serializable value into the mapping of this Bundle, replacing any existing value for the given key.voidputShort(String key, short value)Inserts a short value into the mapping of this Bundle, replacing any existing value for the given key.voidputShortArray(String key, short[] value)Inserts a short array value into the mapping of this Bundle, replacing any existing value for the given key.voidputSize(String key, Size value)Inserts a Size value into the mapping of this Bundle, replacing any existing value for the given key.voidputSizeF(String key, SizeF value)Inserts a SizeF value into the mapping of this Bundle, replacing any existing value for the given key.voidputSparseParcelableArray(String key, SparseArray<? extends Parcelable> value)Inserts a SparceArray of Parcelable values into the mapping of this Bundle, replacing any existing value for the given key.voidputStringArrayList(String key, ArrayList<String> value)Inserts an ArrayListvalue into the mapping of this Bundle, replacing any existing value for the given key. booleansetAllowFds(boolean allowFds)voidsetClassLoader(ClassLoader loader)Changes the ClassLoader this Bundle uses when instantiating objects.StringtoString()Reads the Parcel contents into this Bundle, typically in order for it to be passed through an IBinder connection.voidwriteToParcel(Parcel parcel, int flags)Writes the Bundle contents to a Parcel, typically in order for it to be passed through an IBinder connection.-
Methods inherited from class android.os.BaseBundle
containsKey, get, getDouble, getDouble, getDoubleArray, getInt, getInt, getIntArray, getLong, getLong, getLongArray, getPairValue, getString, getString, getStringArray, isEmpty, isParcelled, keySet, putAll, putDouble, putDoubleArray, putInt, putIntArray, putLong, putLongArray, putString, putStringArray, remove, size
-
-
-
-
Field Detail
-
EMPTY
public static final Bundle EMPTY
-
CREATOR
public static final Parcelable.Creator<Bundle> CREATOR
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.
-
-
Constructor Detail
-
Bundle
public Bundle()
Constructs a new, empty Bundle.
-
Bundle
public Bundle(ClassLoader loader)
Constructs a new, empty Bundle that uses a specific ClassLoader for instantiating Parcelable and Serializable objects.- Parameters:
loader- An explicit ClassLoader to use when instantiating objects inside of the Bundle.
-
Bundle
public Bundle(int capacity)
Constructs a new, empty Bundle sized to hold the given number of elements. The Bundle will grow as needed.- Parameters:
capacity- the initial capacity of the Bundle
-
Bundle
public Bundle(Bundle b)
Constructs a Bundle containing a copy of the mappings from the given Bundle.- Parameters:
b- a Bundle to be copied.
-
Bundle
public Bundle(PersistableBundle b)
Constructs a Bundle containing a copy of the mappings from the given PersistableBundle.- Parameters:
b- a Bundle to be copied.
-
-
Method Detail
-
forPair
public static Bundle forPair(String key, String value)
Make a Bundle for a single key/value pair.
-
setClassLoader
public void setClassLoader(ClassLoader loader)
Changes the ClassLoader this Bundle uses when instantiating objects.- Parameters:
loader- An explicit ClassLoader to use when instantiating objects inside of the Bundle.
-
getClassLoader
public ClassLoader getClassLoader()
Return the ClassLoader currently associated with this Bundle.
-
setAllowFds
public boolean setAllowFds(boolean allowFds)
-
clone
public Object clone()
Clones the current Bundle. The internal map is cloned, but the keys and values to which it refers are copied by reference.
-
clear
public void clear()
Removes all elements from the mapping of this Bundle.- Overrides:
clearin classBaseBundle
-
putAll
public void putAll(Bundle bundle)
Inserts all mappings from the given Bundle into this Bundle.- Parameters:
bundle- a Bundle
-
filterValues
public void filterValues()
Filter values in Bundle to only basic types.
-
putByte
public void putByte(String key, byte value)
Inserts a byte value into the mapping of this Bundle, replacing any existing value for the given key.- Parameters:
key- a String, or nullvalue- a byte
-
putChar
public void putChar(String key, char value)
Inserts a char value into the mapping of this Bundle, replacing any existing value for the given key.- Parameters:
key- a String, or nullvalue- a char, or null
-
putShort
public void putShort(String key, short value)
Inserts a short value into the mapping of this Bundle, replacing any existing value for the given key.- Parameters:
key- a String, or nullvalue- a short
-
putFloat
public void putFloat(String key, float value)
Inserts a float value into the mapping of this Bundle, replacing any existing value for the given key.- Parameters:
key- a String, or nullvalue- a float
-
putCharSequence
public void putCharSequence(String key, 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.- Parameters:
key- a String, or nullvalue- a CharSequence, or null
-
putParcelable
public void putParcelable(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.- Parameters:
key- a String, or nullvalue- a Parcelable object, or null
-
putSize
public void putSize(String key, 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.- Parameters:
key- a String, or nullvalue- a Size object, or null
-
putSizeF
public void putSizeF(String key, 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.- Parameters:
key- a String, or nullvalue- a SizeF object, or null
-
putParcelableArray
public void putParcelableArray(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.- Parameters:
key- a String, or nullvalue- an array of Parcelable objects, or null
-
putParcelableArrayList
public void putParcelableArrayList(String key, ArrayList<? extends Parcelable> 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.- Parameters:
key- a String, or nullvalue- an ArrayList of Parcelable objects, or null
-
putParcelableList
public void putParcelableList(String key, List<? extends Parcelable> value)
-
putSparseParcelableArray
public void putSparseParcelableArray(String key, SparseArray<? extends Parcelable> 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.- Parameters:
key- a String, or nullvalue- a SparseArray of Parcelable objects, or null
-
putIntegerArrayList
public void putIntegerArrayList(String key, ArrayList<Integer> value)
Inserts an ArrayListvalue into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null. - Parameters:
key- a String, or nullvalue- an ArrayListobject, or null
-
putStringArrayList
public void putStringArrayList(String key, ArrayList<String> value)
Inserts an ArrayListvalue into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null. - Parameters:
key- a String, or nullvalue- an ArrayListobject, or null
-
putCharSequenceArrayList
public void putCharSequenceArrayList(String key, ArrayList<CharSequence> value)
Inserts an ArrayListvalue into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null. - Parameters:
key- a String, or nullvalue- an ArrayListobject, or null
-
putSerializable
public void putSerializable(String key, 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.- Parameters:
key- a String, or nullvalue- a Serializable object, or null
-
putByteArray
public void putByteArray(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.- Parameters:
key- a String, or nullvalue- a byte array object, or null
-
putShortArray
public void putShortArray(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.- Parameters:
key- a String, or nullvalue- a short array object, or null
-
putCharArray
public void putCharArray(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.- Parameters:
key- a String, or nullvalue- a char array object, or null
-
putFloatArray
public void putFloatArray(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.- Parameters:
key- a String, or nullvalue- a float array object, or null
-
putCharSequenceArray
public void putCharSequenceArray(String key, 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.- Parameters:
key- a String, or nullvalue- a CharSequence array object, or null
-
putBundle
public void putBundle(String key, 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.- Parameters:
key- a String, or nullvalue- a Bundle object, or null
-
putIBinder
@Deprecated public void putIBinder(String key, IBinder value)
Deprecated.Inserts anIBindervalue 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.
- Parameters:
key- a String, or nullvalue- an IBinder object, or null
-
getByte
public byte getByte(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.- Parameters:
key- a String- Returns:
- a byte value
-
getByte
public Byte getByte(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.- Parameters:
key- a StringdefaultValue- Value to return if key does not exist- Returns:
- a byte value
-
getChar
public char getChar(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.- Parameters:
key- a String- Returns:
- a char value
-
getChar
public char getChar(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.- Parameters:
key- a StringdefaultValue- Value to return if key does not exist- Returns:
- a char value
-
getShort
public short getShort(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.- Parameters:
key- a String- Returns:
- a short value
-
getShort
public short getShort(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.- Parameters:
key- a StringdefaultValue- Value to return if key does not exist- Returns:
- a short value
-
getFloat
public float getFloat(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.- Parameters:
key- a String- Returns:
- a float value
-
getFloat
public float getFloat(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.- Parameters:
key- a StringdefaultValue- Value to return if key does not exist- Returns:
- a float value
-
getCharSequence
public CharSequence getCharSequence(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.- Parameters:
key- a String, or null- Returns:
- a CharSequence value, or null
-
getCharSequence
public CharSequence getCharSequence(String key, 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.- Parameters:
key- a String, or nulldefaultValue- Value to return if key does not exist or if a null value is associated with the given key.- Returns:
- the CharSequence value associated with the given key, or defaultValue if no valid CharSequence object is currently mapped to that key.
-
getSize
public Size getSize(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.- Parameters:
key- a String, or null- Returns:
- a Size value, or null
-
getSizeF
public SizeF getSizeF(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.- Parameters:
key- a String, or null- Returns:
- a Size value, or null
-
getBundle
public Bundle getBundle(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.- Parameters:
key- a String, or null- Returns:
- a Bundle value, or null
-
getParcelable
public <T extends Parcelable> T getParcelable(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.- Parameters:
key- a String, or null- Returns:
- a Parcelable value, or null
-
getParcelableArray
public Parcelable[] getParcelableArray(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.- Parameters:
key- a String, or null- Returns:
- a Parcelable[] value, or null
-
getParcelableArrayList
public <T extends Parcelable> ArrayList<T> getParcelableArrayList(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.- Parameters:
key- a String, or null- Returns:
- an ArrayList
value, or null
-
getSparseParcelableArray
public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(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.- Parameters:
key- a String, or null- Returns:
- a SparseArray of T values, or null
-
getSerializable
public Serializable getSerializable(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.- Parameters:
key- a String, or null- Returns:
- a Serializable value, or null
-
getIntegerArrayList
public ArrayList<Integer> getIntegerArrayList(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.- Parameters:
key- a String, or null- Returns:
- an ArrayList
value, or null
-
getStringArrayList
public ArrayList<String> getStringArrayList(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.- Parameters:
key- a String, or null- Returns:
- an ArrayList
value, or null
-
getCharSequenceArrayList
public ArrayList<CharSequence> getCharSequenceArrayList(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.- Parameters:
key- a String, or null- Returns:
- an ArrayList
value, or null
-
getBooleanArray
public boolean[] getBooleanArray(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.- Parameters:
key- a String, or null- Returns:
- a boolean[] value, or null
-
getByteArray
public byte[] getByteArray(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.- Parameters:
key- a String, or null- Returns:
- a byte[] value, or null
-
getShortArray
public short[] getShortArray(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.- Parameters:
key- a String, or null- Returns:
- a short[] value, or null
-
getCharArray
public char[] getCharArray(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.- Parameters:
key- a String, or null- Returns:
- a char[] value, or null
-
getFloatArray
public float[] getFloatArray(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.- Parameters:
key- a String, or null- Returns:
- a float[] value, or null
-
getCharSequenceArray
public CharSequence[] getCharSequenceArray(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.- Parameters:
key- a String, or null- Returns:
- a CharSequence[] value, or null
-
describeContents
public int describeContents()
Report the nature of this Parcelable's contents- Specified by:
describeContentsin interfaceParcelable- Returns:
- a bitmask indicating the set of special object types marshalled by the Parcelable.
-
writeToParcel
public void writeToParcel(Parcel parcel, int flags)
Writes the Bundle contents to a Parcel, typically in order for it to be passed through an IBinder connection.- Specified by:
writeToParcelin interfaceParcelable- Parameters:
parcel- The parcel to copy this bundle to.flags- Additional flags about how the object should be written. May be 0 orParcelable.PARCELABLE_WRITE_RETURN_VALUE.
-
-