Bundle
public
final
class
Bundle
extends BaseBundle
implements
Cloneable,
Parcelable
java.lang.Object | ||
↳ | android.os.BaseBundle | |
↳ | android.os.Bundle |
A mapping from String keys to various Parcelable
values.
Warning: Note that Bundle
is a lazy container and as such it does NOT implement
Object.equals(java.lang.Object)
or Object.hashCode()
.
See also:
Summary
Inherited constants | ||||
---|---|---|---|---|
|
Fields | |
---|---|
public
static
final
Creator<Bundle> |
CREATOR
|
public
static
final
Bundle |
EMPTY
An unmodifiable |
Public constructors | |
---|---|
Bundle()
Constructs a new, empty 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. |
|
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. |
Public methods | |
---|---|
void
|
clear()
Removes all elements from the mapping of this Bundle. |
Object
|
clone()
Clones the current Bundle. |
Bundle
|
deepCopy()
Make a deep copy of the given bundle. |
int
|
describeContents()
Report the nature of this Parcelable's contents |
IBinder
|
getBinder(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 (char) 0 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 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. |
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. |
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[]
|
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. |
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
|
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[]
|
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>
T
|
getParcelable(String key)
This method was deprecated
in API level 33.
Use the type-safer |
<T>
T
|
getParcelable(String key, Class<T> clazz)
Returns the value associated with the given key or
|
<T>
T[]
|
getParcelableArray(String key, Class<T> clazz)
Returns the value associated with the given key, or
|
Parcelable[]
|
getParcelableArray(String key)
This method was deprecated
in API level 33.
Use the type-safer |
<T>
ArrayList<T>
|
getParcelableArrayList(String key, Class<? extends T> clazz)
Returns the value associated with the given key, or
|
<T extends Parcelable>
ArrayList<T>
|
getParcelableArrayList(String key)
This method was deprecated
in API level 33.
Use the type-safer |
<T extends Serializable>
T
|
getSerializable(String key, Class<T> clazz)
Returns the value associated with the given key, or
|
Serializable
|
getSerializable(String key)
This method was deprecated
in API level 33.
Use the type-safer |
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. |
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. |
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. |
<T extends Parcelable>
SparseArray<T>
|
getSparseParcelableArray(String key)
This method was deprecated
in API level 33.
Use the type-safer |
<T>
SparseArray<T>
|
getSparseParcelableArray(String key, Class<? extends T> clazz)
Returns the value associated with the given key, or
|
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. |
void
|
putAll(Bundle bundle)
Inserts all mappings from the given Bundle into this Bundle. |
void
|
putBinder(String key, IBinder value)
Inserts an |
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
|
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
|
putIntegerArrayList(String key, ArrayList<Integer> value)
Inserts an ArrayList |
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
|
putSize(String key, Size value)
Inserts a Size value into the mapping of this Bundle, replacing any existing value for the given key. |
void
|
putSizeF(String key, SizeF value)
Inserts a SizeF 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
|
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. |
void
|
setClassLoader(ClassLoader loader)
Changes the ClassLoader this Bundle uses when instantiating objects. |
String
|
toString()
Returns a string representation of the |
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. |
Inherited methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Fields
EMPTY
public static final Bundle EMPTY
An unmodifiable Bundle
that is always empty
.
Public constructors
Bundle
public Bundle (ClassLoader loader)
Constructs a new, empty Bundle that uses a specific ClassLoader for instantiating Parcelable and Serializable objects.
Parameters | |
---|---|
loader |
ClassLoader : 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 |
int : the initial capacity of the Bundle |
Bundle
public Bundle (Bundle b)
Constructs a Bundle containing a copy of the mappings from the given
Bundle. Does only a shallow copy of the original Bundle -- see
deepCopy()
if that is not what you want.
Parameters | |
---|---|
b |
Bundle : a Bundle to be copied. |
See also:
Bundle
public Bundle (PersistableBundle b)
Constructs a Bundle containing a copy of the mappings from the given
PersistableBundle. Does only a shallow copy of the PersistableBundle -- see
PersistableBundle#deepCopy()
if you don't want that.
Parameters | |
---|---|
b |
PersistableBundle : a PersistableBundle to be copied. |
Public methods
clear
public void clear ()
Removes all elements from the mapping of this Bundle.
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.
Returns | |
---|---|
Object |
a clone of this instance. |
deepCopy
public Bundle deepCopy ()
Make a deep copy of the given bundle. Traverses into inner containers and copies
them as well, so they are not shared across bundles. Will traverse in to
Bundle
, PersistableBundle
, ArrayList
, and all types of
primitive arrays. Other types of objects (such as Parcelable or Serializable)
are referenced as-is and not copied in any way.
Returns | |
---|---|
Bundle |
describeContents
public int describeContents ()
Report the nature of this Parcelable's contents
Returns | |
---|---|
int |
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0 or CONTENTS_FILE_DESCRIPTOR |
getBinder
public IBinder getBinder (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 |
String : a String, or null |
Returns | |
---|---|
IBinder |
an IBinder 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 |
String : a String, or null |
Returns | |
---|---|
Bundle |
a Bundle value, 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 |
String : a String |
Returns | |
---|---|
byte |
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 |
String : a String |
defaultValue |
byte : Value to return if key does not exist |
Returns | |
---|---|
Byte |
a byte value |
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 |
String : a String, or null |
Returns | |
---|---|
byte[] |
a byte[] value, or null |
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 |
String : a String |
Returns | |
---|---|
char |
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 |
String : a String |
defaultValue |
char : Value to return if key does not exist |
Returns | |
---|---|
char |
a char value |
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 |
String : a String, or null |
Returns | |
---|---|
char[] |
a char[] 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 |
String : a String, or null |
defaultValue |
CharSequence : Value to return if key does not exist or if a null
value is associated with the given key. |
Returns | |
---|---|
CharSequence |
the CharSequence value associated with the given key, or defaultValue if no valid CharSequence object is currently mapped to that key. |
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 |
String : a String, or null |
Returns | |
---|---|
CharSequence |
a CharSequence 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 |
String : a String, or null |
Returns | |
---|---|
CharSequence[] |
a CharSequence[] 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 |
String : a String, or null |
Returns | |
---|---|
ArrayList<CharSequence> |
an ArrayList |
getClassLoader
public ClassLoader getClassLoader ()
Return the ClassLoader currently associated with this Bundle.
Returns | |
---|---|
ClassLoader |
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 |
String : a String |
defaultValue |
float : Value to return if key does not exist |
Returns | |
---|---|
float |
a float 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 |
String : a String |
Returns | |
---|---|
float |
a float value |
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 |
String : a String, or null |
Returns | |
---|---|
float[] |
a float[] 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 |
String : a String, or null |
getParcelable
public T getParcelable (String key)
This method was deprecated
in API level 33.
Use the type-safer getParcelable(java.lang.String, java.lang.Class)
starting from Android
Build.VERSION_CODES#TIRAMISU
.
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.
Note: if the expected value is not a class provided by the Android platform,
you must call setClassLoader(java.lang.ClassLoader)
with the proper ClassLoader
first.
Otherwise, this method might throw an exception or return null
.
Parameters | |
---|---|
key |
String : a String, or null |
Returns | |
---|---|
T |
a Parcelable value, or null |
getParcelable
public T getParcelable (String key, Class<T> clazz)
Returns the value associated with the given key or null
if:
- No mapping of the desired type exists for the given key.
- A
null
value is explicitly associated with the key. - The object is not of type
clazz
.
Note: if the expected value is not a class provided by the Android platform,
you must call setClassLoader(java.lang.ClassLoader)
with the proper ClassLoader
first.
Otherwise, this method might throw an exception or return null
.
Warning: the class that implements Parcelable
has to be the immediately
enclosing class of the runtime type of its CREATOR field (that is,
Class#getEnclosingClass()
has to return the parcelable implementing class),
otherwise this method might throw an exception. If the Parcelable class does not enclose the
CREATOR, use the deprecated getParcelable(java.lang.String)
instead.
Parameters | |
---|---|
key |
String : a String, or null |
clazz |
Class : The type of the object expected
This value cannot be null . |
Returns | |
---|---|
T |
a Parcelable value, or null |
getParcelableArray
public T[] getParcelableArray (String key, Class<T> clazz)
Returns the value associated with the given key, or null
if:
- No mapping of the desired type exists for the given key.
- A
null
value is explicitly associated with the key. - The object is not of type
clazz
.
Note: if the expected value is not a class provided by the Android platform,
you must call setClassLoader(java.lang.ClassLoader)
with the proper ClassLoader
first.
Otherwise, this method might throw an exception or return null
.
Warning: if the list contains items implementing the Parcelable
interface,
the class that implements Parcelable
has to be the immediately
enclosing class of the runtime type of its CREATOR field (that is,
Class#getEnclosingClass()
has to return the parcelable implementing class),
otherwise this method might throw an exception. If the Parcelable class does not enclose the
CREATOR, use the deprecated getParcelableArray(java.lang.String)
instead.
Parameters | |
---|---|
key |
String : a String, or null |
clazz |
Class : The type of the items inside the array. This is only verified when unparceling.
This value cannot be null . |
Returns | |
---|---|
T[] |
a Parcelable[] value, or null |
getParcelableArray
public Parcelable[] getParcelableArray (String key)
This method was deprecated
in API level 33.
Use the type-safer getParcelableArray(java.lang.String, java.lang.Class)
starting from
Android Build.VERSION_CODES#TIRAMISU
.
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.
Note: if the expected value is not a class provided by the Android platform,
you must call setClassLoader(java.lang.ClassLoader)
with the proper ClassLoader
first.
Otherwise, this method might throw an exception or return null
.
Parameters | |
---|---|
key |
String : a String, or null |
Returns | |
---|---|
Parcelable[] |
a Parcelable[] value, or null |
getParcelableArrayList
public ArrayList<T> getParcelableArrayList (String key, Class<? extends T> clazz)
Returns the value associated with the given key, or null
if:
- No mapping of the desired type exists for the given key.
- A
null
value is explicitly associated with the key. - The object is not of type
clazz
.
Note: if the expected value is not a class provided by the Android platform,
you must call setClassLoader(java.lang.ClassLoader)
with the proper ClassLoader
first.
Otherwise, this method might throw an exception or return null
.
Warning: if the list contains items implementing the Parcelable
interface,
the class that implements Parcelable
has to be the immediately
enclosing class of the runtime type of its CREATOR field (that is,
Class#getEnclosingClass()
has to return the parcelable implementing class),
otherwise this method might throw an exception. If the Parcelable class does not enclose the
CREATOR, use the deprecated getParcelableArrayList(java.lang.String)
instead.
Parameters | |
---|---|
key |
String : a String, or null |
clazz |
Class : The type of the items inside the array list. This is only verified when
unparceling.
This value cannot be null . |
Returns | |
---|---|
ArrayList<T> |
an ArrayListnull |
getParcelableArrayList
public ArrayList<T> getParcelableArrayList (String key)
This method was deprecated
in API level 33.
Use the type-safer getParcelable(java.lang.String, java.lang.Class)
starting from Android
Build.VERSION_CODES#TIRAMISU
.
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.
Note: if the expected value is not a class provided by the Android platform,
you must call setClassLoader(java.lang.ClassLoader)
with the proper ClassLoader
first.
Otherwise, this method might throw an exception or return null
.
Parameters | |
---|---|
key |
String : a String, or null |
Returns | |
---|---|
ArrayList<T> |
an ArrayListnull |
getSerializable
public T getSerializable (String key, Class<T> clazz)
Returns the value associated with the given key, or null
if:
- No mapping of the desired type exists for the given key.
- A
null
value is explicitly associated with the key. - The object is not of type
clazz
.
Parameters | |
---|---|
key |
String : a String, or null |
clazz |
Class : The expected class of the returned type
This value cannot be null . |
Returns | |
---|---|
T |
a Serializable value, or null |
getSerializable
public Serializable getSerializable (String key)
This method was deprecated
in API level 33.
Use the type-safer getSerializable(java.lang.String, java.lang.Class)
starting from Android
Build.VERSION_CODES#TIRAMISU
.
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 |
String : a String, or null |
Returns | |
---|---|
Serializable |
a Serializable value, or null |
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 |
String : a String |
Returns | |
---|---|
short |
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 |
String : a String |
defaultValue |
short : Value to return if key does not exist |
Returns | |
---|---|
short |
a short value |
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 |
String : a String, or null |
Returns | |
---|---|
short[] |
a short[] value, or null |
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 |
String : a String, or null |
Returns | |
---|---|
Size |
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 |
String : a String, or null |
Returns | |
---|---|
SizeF |
a Size value, or null |
getSparseParcelableArray
public SparseArray<T> getSparseParcelableArray (String key)
This method was deprecated
in API level 33.
Use the type-safer getSparseParcelableArray(java.lang.String, java.lang.Class)
starting from
Android Build.VERSION_CODES#TIRAMISU
.
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 |
String : a String, or null |
Returns | |
---|---|
SparseArray<T> |
a SparseArray of T values, or null |
getSparseParcelableArray
public SparseArray<T> getSparseParcelableArray (String key, Class<? extends T> clazz)
Returns the value associated with the given key, or null
if:
- No mapping of the desired type exists for the given key.
- A
null
value is explicitly associated with the key. - The object is not of type
clazz
.
Warning: if the list contains items implementing the Parcelable
interface,
the class that implements Parcelable
has to be the immediately
enclosing class of the runtime type of its CREATOR field (that is,
Class#getEnclosingClass()
has to return the parcelable implementing class),
otherwise this method might throw an exception. If the Parcelable class does not enclose the
CREATOR, use the deprecated getSparseParcelableArray(java.lang.String)
instead.
Parameters | |
---|---|
key |
String : a String, or null |
clazz |
Class : The type of the items inside the sparse array. This is only verified when
unparceling.
This value cannot be null . |
Returns | |
---|---|
SparseArray<T> |
a SparseArray of T values, 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 |
String : a String, or null |
hasFileDescriptors
public boolean hasFileDescriptors ()
Reports whether the bundle contains any parcelled file descriptors.
Returns | |
---|---|
boolean |
putAll
public void putAll (Bundle bundle)
Inserts all mappings from the given Bundle into this Bundle.
Parameters | |
---|---|
bundle |
Bundle : a Bundle |
putBinder
public void putBinder (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.
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 |
String : a String, or null |
value |
IBinder : an IBinder 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 |
String : a String, or null |
value |
Bundle : a Bundle object, or null |
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 |
String : a String, or null |
value |
byte : a byte |
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 |
String : a String, or null |
value |
byte : a byte array object, or null |
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 |
String : a String, or null |
value |
char : a char |
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 |
String : a String, or null |
value |
char : a char array object, or null |
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 |
String : a String, or null |
value |
CharSequence : a CharSequence, 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 |
String : a String, or null |
value |
CharSequence : a CharSequence array object, or null |
putCharSequenceArrayList
public void putCharSequenceArrayList (String key, ArrayList<CharSequence> value)
Inserts an ArrayList
Parameters | |
---|---|
key |
String : a String, or null |
value |
ArrayList : an ArrayList |
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 |
String : a String, or null |
value |
float : a float |
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 |
String : a String, or null |
value |
float : a float array object, or null |
putIntegerArrayList
public void putIntegerArrayList (String key, ArrayList<Integer> value)
Inserts an ArrayList
Parameters | |
---|---|
key |
String : a String, or null |
value |
ArrayList : an ArrayList |
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 |
String : a String, or null |
value |
Parcelable : a Parcelable 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 |
String : a String, or null |
value |
Parcelable : 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 |
String : a String, or null |
value |
ArrayList : an ArrayList of Parcelable objects, 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 |
String : a String, or null |
value |
Serializable : a Serializable object, 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 |
String : a String, or null |
value |
short : a short |
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 |
String : a String, or null |
value |
short : a short array 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 |
String : a String, or null |
value |
Size : 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 |
String : a String, or null |
value |
SizeF : a SizeF object, or null |
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 |
String : a String, or null |
value |
SparseArray : a SparseArray of Parcelable objects, or null |
putStringArrayList
public void putStringArrayList (String key, ArrayList<String> value)
Inserts an ArrayList
Parameters | |
---|---|
key |
String : a String, or null |
value |
ArrayList : an ArrayList |
readFromParcel
public void readFromParcel (Parcel parcel)
Reads the Parcel contents into this Bundle, typically in order for it to be passed through an IBinder connection.
Parameters | |
---|---|
parcel |
Parcel : The parcel to overwrite this bundle from. |
remove
public void remove (String key)
Removes any entry with the given key from the mapping of this Bundle.
Parameters | |
---|---|
key |
String : a String key |
setClassLoader
public void setClassLoader (ClassLoader loader)
Changes the ClassLoader this Bundle uses when instantiating objects.
Parameters | |
---|---|
loader |
ClassLoader : An explicit ClassLoader to use when instantiating objects
inside of the Bundle. |
toString
public String toString ()
Returns a string representation of the Bundle
that may be suitable for debugging. It
won't print the internal map if its content hasn't been unparcelled.
Returns | |
---|---|
String |
a string representation of the object. |
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.
Parameters | |
---|---|
parcel |
Parcel : The parcel to copy this bundle to. |
flags |
int : Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE .
Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |