public final class Bundle extends Object implements Parcelable, Cloneable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<Bundle> |
CREATOR |
static Bundle |
EMPTY |
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
Bundle()
Constructs a new, empty Bundle.
|
Bundle(Bundle b)
Constructs a Bundle containing a copy of the mappings from the given
Bundle.
|
Bundle(ClassLoader loader)
Constructs a new, empty Bundle that uses a specific ClassLoader for
instantiating Parcelable and Serializable objects.
|
Bundle(int capacity)
Constructs a new, empty Bundle sized to hold the given number of
elements.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all elements from the mapping of this Bundle.
|
Object |
clone()
Clones the current Bundle.
|
boolean |
containsKey(String key)
Returns true if the given key is contained in the mapping
of this Bundle.
|
int |
describeContents()
Report the nature of this Parcelable's contents
|
static Bundle |
forPair(String key,
String value)
Make a Bundle for a single key/value pair.
|
Object |
get(String key)
Returns the entry with the given key as an object.
|
boolean |
getBoolean(String key)
Returns the value associated with the given key, or false if
no mapping of the desired type exists for the given key.
|
boolean |
getBoolean(String key,
boolean defaultValue)
Returns the value associated with the given key, or defaultValue if
no mapping of the desired type exists for the given key.
|
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.
|
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.
|
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.
|
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.
|
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.
|
char |
getChar(String key)
Returns the value associated with the given key, or false if
no mapping of the desired type exists for the given key.
|
char |
getChar(String key,
char defaultValue)
Returns the value associated with the given key, or (char) 0 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.
|
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.
|
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.
|
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.
|
ClassLoader |
getClassLoader()
Return the ClassLoader currently associated with this Bundle.
|
double |
getDouble(String key)
Returns the value associated with the given key, or 0.0 if
no mapping of the desired type exists for the given key.
|
double |
getDouble(String key,
double defaultValue)
Returns the value associated with the given key, or defaultValue if
no mapping of the desired type exists for the given key.
|
double[] |
getDoubleArray(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.
|
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.
|
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.
|
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.
|
IBinder |
getIBinder(String key)
Deprecated.
|
int |
getInt(String key)
Returns the value associated with the given key, or 0 if
no mapping of the desired type exists for the given key.
|
int |
getInt(String key,
int defaultValue)
Returns the value associated with the given key, or defaultValue if
no mapping of the desired type exists for the given key.
|
int[] |
getIntArray(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.
|
long |
getLong(String key)
Returns the value associated with the given key, or 0L if
no mapping of the desired type exists for the given key.
|
long |
getLong(String key,
long defaultValue)
Returns the value associated with the given key, or defaultValue if
no mapping of the desired type exists for the given key.
|
long[] |
getLongArray(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.
|
String |
getPairValue()
TODO: optimize this later (getting just the value part of a Bundle
with a single pair) once Bundle.forPair() above is implemented
with a special single-value Map implementation/serialization.
|
<T extends Parcelable> |
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.
|
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> |
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.
|
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.
|
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.
|
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.
|
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.
|
<T extends Parcelable> |
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.
|
String |
getString(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.
|
String |
getString(String key,
String defaultValue)
Returns the value associated with the given key, or defaultValue if
no mapping of the desired type exists for the given key.
|
String[] |
getStringArray(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.
|
boolean |
hasFileDescriptors()
Reports whether the bundle contains any parcelled file descriptors.
|
boolean |
isEmpty()
Returns true if the mapping of this Bundle is empty, false otherwise.
|
boolean |
isParcelled() |
Set<String> |
keySet()
Returns a Set containing the Strings used as keys in this Bundle.
|
void |
putAll(Bundle map)
Inserts all mappings from the given Bundle into this Bundle.
|
void |
putBoolean(String key,
boolean value)
Inserts a Boolean value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putBooleanArray(String key,
boolean[] value)
Inserts a boolean array value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putBundle(String key,
Bundle value)
Inserts a Bundle value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putByte(String key,
byte value)
Inserts a byte value into the mapping of this Bundle, replacing
any existing value for the given key.
|
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.
|
void |
putChar(String key,
char value)
Inserts a char value into the mapping of this Bundle, replacing
any existing value for the given key.
|
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.
|
void |
putCharSequence(String key,
CharSequence value)
Inserts a CharSequence value into the mapping of this Bundle, replacing
any existing value for the given key.
|
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.
|
void |
putCharSequenceArrayList(String key,
ArrayList<CharSequence> value)
Inserts an ArrayList
|
void |
putDouble(String key,
double value)
Inserts a double value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putDoubleArray(String key,
double[] value)
Inserts a double array value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putFloat(String key,
float value)
Inserts a float value into the mapping of this Bundle, replacing
any existing value for the given key.
|
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.
|
void |
putIBinder(String key,
IBinder value)
Deprecated.
|
void |
putInt(String key,
int value)
Inserts an int value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putIntArray(String key,
int[] value)
Inserts an int array value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putIntegerArrayList(String key,
ArrayList<Integer> value)
Inserts an ArrayList
|
void |
putLong(String key,
long value)
Inserts a long value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putLongArray(String key,
long[] value)
Inserts a long array value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putParcelable(String key,
Parcelable value)
Inserts a Parcelable value into the mapping of this Bundle, replacing
any existing value for the given key.
|
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.
|
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.
|
void |
putSerializable(String key,
Serializable value)
Inserts a Serializable value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putShort(String key,
short value)
Inserts a short value into the mapping of this Bundle, replacing
any existing value for the given key.
|
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.
|
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.
|
void |
putString(String key,
String value)
Inserts a String value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putStringArray(String key,
String[] value)
Inserts a String array value into the mapping of this Bundle, replacing
any existing value for the given key.
|
void |
putStringArrayList(String key,
ArrayList<String> value)
Inserts an ArrayList
|
void |
readFromParcel(Parcel parcel)
Reads the Parcel contents into this Bundle, typically in order for
it to be passed through an IBinder connection.
|
void |
remove(String key)
Removes any entry with the given key from the mapping of this Bundle.
|
boolean |
setAllowFds(boolean allowFds) |
void |
setClassLoader(ClassLoader loader)
Changes the ClassLoader this Bundle uses when instantiating objects.
|
int |
size()
Returns the number of mappings contained in this Bundle.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
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.
|
public static final Bundle EMPTY
public static final Parcelable.Creator<Bundle> CREATOR
public Bundle()
public Bundle(ClassLoader loader)
loader
- An explicit ClassLoader to use when instantiating objects
inside of the Bundle.public Bundle(int capacity)
capacity
- the initial capacity of the Bundlepublic Bundle(Bundle b)
b
- a Bundle to be copied.public static Bundle forPair(String key, String value)
public String getPairValue()
public void setClassLoader(ClassLoader loader)
loader
- An explicit ClassLoader to use when instantiating objects
inside of the Bundle.public ClassLoader getClassLoader()
public boolean setAllowFds(boolean allowFds)
public Object clone()
public boolean isParcelled()
public int size()
public boolean isEmpty()
public void clear()
public boolean containsKey(String key)
key
- a String keypublic Object get(String key)
key
- a String keypublic void remove(String key)
key
- a String keypublic void putAll(Bundle map)
map
- a Bundlepublic Set<String> keySet()
public boolean hasFileDescriptors()
public void putBoolean(String key, boolean value)
key
- a String, or nullvalue
- a Boolean, or nullpublic void putByte(String key, byte value)
key
- a String, or nullvalue
- a bytepublic void putChar(String key, char value)
key
- a String, or nullvalue
- a char, or nullpublic void putShort(String key, short value)
key
- a String, or nullvalue
- a shortpublic void putInt(String key, int value)
key
- a String, or nullvalue
- an int, or nullpublic void putLong(String key, long value)
key
- a String, or nullvalue
- a longpublic void putFloat(String key, float value)
key
- a String, or nullvalue
- a floatpublic void putDouble(String key, double value)
key
- a String, or nullvalue
- a doublepublic void putString(String key, String value)
key
- a String, or nullvalue
- a String, or nullpublic void putCharSequence(String key, CharSequence value)
key
- a String, or nullvalue
- a CharSequence, or nullpublic void putParcelable(String key, Parcelable value)
key
- a String, or nullvalue
- a Parcelable object, or nullpublic void putParcelableArray(String key, Parcelable[] value)
key
- a String, or nullvalue
- an array of Parcelable objects, or nullpublic void putParcelableArrayList(String key, ArrayList<? extends Parcelable> value)
key
- a String, or nullvalue
- an ArrayList of Parcelable objects, or nullpublic void putSparseParcelableArray(String key, SparseArray<? extends Parcelable> value)
key
- a String, or nullvalue
- a SparseArray of Parcelable objects, or nullpublic void putIntegerArrayList(String key, ArrayList<Integer> value)
key
- a String, or nullvalue
- an ArrayListpublic void putStringArrayList(String key, ArrayList<String> value)
key
- a String, or nullvalue
- an ArrayListpublic void putCharSequenceArrayList(String key, ArrayList<CharSequence> value)
key
- a String, or nullvalue
- an ArrayListpublic void putSerializable(String key, Serializable value)
key
- a String, or nullvalue
- a Serializable object, or nullpublic void putBooleanArray(String key, boolean[] value)
key
- a String, or nullvalue
- a boolean array object, or nullpublic void putByteArray(String key, byte[] value)
key
- a String, or nullvalue
- a byte array object, or nullpublic void putShortArray(String key, short[] value)
key
- a String, or nullvalue
- a short array object, or nullpublic void putCharArray(String key, char[] value)
key
- a String, or nullvalue
- a char array object, or nullpublic void putIntArray(String key, int[] value)
key
- a String, or nullvalue
- an int array object, or nullpublic void putLongArray(String key, long[] value)
key
- a String, or nullvalue
- a long array object, or nullpublic void putFloatArray(String key, float[] value)
key
- a String, or nullvalue
- a float array object, or nullpublic void putDoubleArray(String key, double[] value)
key
- a String, or nullvalue
- a double array object, or nullpublic void putStringArray(String key, String[] value)
key
- a String, or nullvalue
- a String array object, or nullpublic void putCharSequenceArray(String key, CharSequence[] value)
key
- a String, or nullvalue
- a CharSequence array object, or nullpublic void putBundle(String key, Bundle value)
key
- a String, or nullvalue
- a Bundle object, or null@Deprecated public void putIBinder(String key, IBinder value)
key
- a String, or nullvalue
- an IBinder object, or nullpublic boolean getBoolean(String key)
key
- a Stringpublic boolean getBoolean(String key, boolean defaultValue)
key
- a Stringpublic byte getByte(String key)
key
- a Stringpublic Byte getByte(String key, byte defaultValue)
key
- a Stringpublic char getChar(String key)
key
- a Stringpublic char getChar(String key, char defaultValue)
key
- a Stringpublic short getShort(String key)
key
- a Stringpublic short getShort(String key, short defaultValue)
key
- a Stringpublic int getInt(String key)
key
- a Stringpublic int getInt(String key, int defaultValue)
key
- a Stringpublic long getLong(String key)
key
- a Stringpublic long getLong(String key, long defaultValue)
key
- a Stringpublic float getFloat(String key)
key
- a Stringpublic float getFloat(String key, float defaultValue)
key
- a Stringpublic double getDouble(String key)
key
- a Stringpublic double getDouble(String key, double defaultValue)
key
- a Stringpublic String getString(String key)
key
- a String, or nullpublic String getString(String key, String defaultValue)
key
- a String, or nulldefaultValue
- Value to return if key does not existpublic CharSequence getCharSequence(String key)
key
- a String, or nullpublic CharSequence getCharSequence(String key, CharSequence defaultValue)
key
- a String, or nulldefaultValue
- Value to return if key does not existpublic Bundle getBundle(String key)
key
- a String, or nullpublic <T extends Parcelable> T getParcelable(String key)
key
- a String, or nullpublic Parcelable[] getParcelableArray(String key)
key
- a String, or nullpublic <T extends Parcelable> ArrayList<T> getParcelableArrayList(String key)
key
- a String, or nullpublic <T extends Parcelable> SparseArray<T> getSparseParcelableArray(String key)
key
- a String, or nullpublic Serializable getSerializable(String key)
key
- a String, or nullpublic ArrayList<Integer> getIntegerArrayList(String key)
key
- a String, or nullpublic ArrayList<String> getStringArrayList(String key)
key
- a String, or nullpublic ArrayList<CharSequence> getCharSequenceArrayList(String key)
key
- a String, or nullpublic boolean[] getBooleanArray(String key)
key
- a String, or nullpublic byte[] getByteArray(String key)
key
- a String, or nullpublic short[] getShortArray(String key)
key
- a String, or nullpublic char[] getCharArray(String key)
key
- a String, or nullpublic int[] getIntArray(String key)
key
- a String, or nullpublic long[] getLongArray(String key)
key
- a String, or nullpublic float[] getFloatArray(String key)
key
- a String, or nullpublic double[] getDoubleArray(String key)
key
- a String, or nullpublic String[] getStringArray(String key)
key
- a String, or nullpublic CharSequence[] getCharSequenceArray(String key)
key
- a String, or null@Deprecated public IBinder getIBinder(String key)
key
- a String, or nullpublic int describeContents()
describeContents
in interface Parcelable
public void writeToParcel(Parcel parcel, int flags)
writeToParcel
in interface Parcelable
parcel
- The parcel to copy this bundle to.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public void readFromParcel(Parcel parcel)
parcel
- The parcel to overwrite this bundle from.public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.