BundleCompat


class BundleCompat


Helper for accessing features in Bundle.

Summary

Public functions

java-static IBinder?
@ReplaceWith(expression = "bundle.getBinder(key)")
getBinder(bundle: Bundle, key: String?)

This function is deprecated.

Use getBinder directly.

java-static T?
<T> getParcelable(in: Bundle, key: String?, clazz: Class<T!>)

Returns the value associated with the given key or null if:

java-static Array<Parcelable!>?
getParcelableArray(in: Bundle, key: String?, clazz: Class<Parcelable!>)

Returns the value associated with the given key, or null if:

java-static ArrayList<T!>?
<T> getParcelableArrayList(in: Bundle, key: String?, clazz: Class<T!>)

Returns the value associated with the given key, or null if:

java-static T?
<T : Serializable?> getSerializable(in: Bundle, key: String?, clazz: Class<T!>)

Returns the value associated with the given key or null if:

java-static SparseArray<T!>?
<T> getSparseParcelableArray(in: Bundle, key: String?, clazz: Class<T!>)

Returns the value associated with the given key, or null if:

java-static Unit
@ReplaceWith(expression = "bundle.putBinder(key, binder)")
putBinder(bundle: Bundle, key: String?, binder: IBinder?)

This function is deprecated.

Use putBinder directly.

Public functions

getBinder

Added in 1.11.0
Deprecated in 1.13.0
@ReplaceWith(expression = "bundle.getBinder(key)")
java-static fun getBinder(bundle: Bundle, key: String?): IBinder?

A convenience method to handle getting an IBinder inside a Bundle for all Android versions.

Parameters
bundle: Bundle

The bundle to get the IBinder.

key: String?

The key to use while getting the IBinder.

Returns
IBinder?

The IBinder that was obtained.

getParcelable

Added in 1.10.0
java-static fun <T> getParcelable(in: Bundle, key: String?, clazz: Class<T!>): T?

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 with the proper ClassLoader first. Otherwise, this method might throw an exception or return null.

Compatibility behavior:

  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, the object type is checked after deserialization.
Parameters
in: Bundle

The bundle to retrieve from.

key: String?

a String, or null

clazz: Class<T!>

The type of the object expected

Returns
T?

a Parcelable value, or null

getParcelableArray

Added in 1.10.0
java-static fun getParcelableArray(in: Bundle, key: String?, clazz: Class<Parcelable!>): Array<Parcelable!>?

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 with the proper ClassLoader first. Otherwise, this method might throw an exception or return null.

Compatibility behavior:

  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, this method will not check the array elements' types.
Parameters
in: Bundle

The bundle to retrieve from.

key: String?

a String, or null

clazz: Class<Parcelable!>

The type of the items inside the array. This is only verified when unparceling.

Returns
Array<Parcelable!>?

a Parcelable[] value, or null

getParcelableArrayList

Added in 1.10.0
java-static fun <T> getParcelableArrayList(in: Bundle, key: String?, clazz: Class<T!>): ArrayList<T!>?

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 with the proper ClassLoader first. Otherwise, this method might throw an exception or return null.

Compatibility behavior:

  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, this method will not check the list elements' types.
Parameters
in: Bundle

The bundle to retrieve from.

key: String?

a String, or null

clazz: Class<T!>

The type of the items inside the array list. This is only verified when unparceling.

Returns
ArrayList<T!>?

an ArrayListvalue, or

getSerializable

Added in 1.13.0
java-static fun <T : Serializable?> getSerializable(in: Bundle, key: String?, clazz: Class<T!>): T?

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.
Compatibility behavior:
  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, the object type is checked after deserialization.
Parameters
in: Bundle

The bundle to retrieve from.

key: String?

a String, or null

clazz: Class<T!>

The type of the object expected

Returns
T?

a Serializable value, or null

getSparseParcelableArray

Added in 1.10.0
java-static fun <T> getSparseParcelableArray(in: Bundle, key: String?, clazz: Class<T!>): SparseArray<T!>?

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.
Compatibility behavior:
  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, this method will not check the array elements' types.
Parameters
in: Bundle

The bundle to retrieve from.

key: String?

a String, or null

clazz: Class<T!>

The type of the items inside the sparse array. This is only verified when unparceling.

Returns
SparseArray<T!>?

a SparseArray of T values, or null

putBinder

Added in 1.11.0
Deprecated in 1.13.0
@ReplaceWith(expression = "bundle.putBinder(key, binder)")
java-static fun putBinder(bundle: Bundle, key: String?, binder: IBinder?): Unit

A convenience method to handle putting an IBinder inside a Bundle for all Android versions.

Parameters
bundle: Bundle

The bundle to insert the IBinder.

key: String?

The key to use while putting the IBinder.

binder: IBinder?

The IBinder to put.