# BundleCompat

# BundleCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/os/BundleCompat.java+class:androidx.core.os.BundleCompat)  
Added in[1.10.0](https://developer.android.com/jetpack/androidx/releases/core#1.10.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/os/BundleCompat "View this page in Java")

<br />

```
class BundleCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[Bundle](https://developer.android.com/reference/android/os/Bundle.html).

## Summary

|                                                                                 ### Public functions                                                                                  |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[IBinder](https://developer.android.com/reference/android/os/IBinder.html)`?`                                                                                           | `@`[ReplaceWith](https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith)`(expression = "bundle.getBinder(key)")` ~~[getBinder](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getBinder(android.os.Bundle,java.lang.String))~~`(bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?)` **This function is deprecated.** Use[getBinder](https://developer.android.com/reference/android/os/Bundle.html#getBinder(java.lang.String))directly. <br />                                                                                                                                       |
| `java-static T?`                                                                                                                                                                      | `<T> `[getParcelable](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getParcelable(android.os.Bundle,java.lang.String,java.lang.Class<T>))`(in: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>)` Returns the value associated with the given key or`null`if:                                                                                                                                                                                                                                                                   |
| `java-static `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`!>?` | [getParcelableArray](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getParcelableArray(android.os.Bundle,java.lang.String,java.lang.Class<? extends android.os.Parcelable>))`(in: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<`[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`!>)` Returns the value associated with the given key, or`null`if:                                                                                                                                               |
| `java-static `[ArrayList](https://developer.android.com/reference/java/util/ArrayList.html)`<T!>?`                                                                                    | `<T> `[getParcelableArrayList](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getParcelableArrayList(android.os.Bundle,java.lang.String,java.lang.Class<? extends T>))`(in: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>)` Returns the value associated with the given key, or`null`if:                                                                                                                                                                                                                                      |
| `java-static T?`                                                                                                                                                                      | `<T : `[Serializable](https://developer.android.com/reference/java/io/Serializable.html)`?> `[getSerializable](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getSerializable(android.os.Bundle,java.lang.String,java.lang.Class<T>))`(in: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>)` Returns the value associated with the given key or`null`if:                                                                                                                                                                        |
| `java-static `[SparseArray](https://developer.android.com/reference/android/util/SparseArray.html)`<T!>?`                                                                             | `<T> `[getSparseParcelableArray](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getSparseParcelableArray(android.os.Bundle,java.lang.String,java.lang.Class<? extends T>))`(in: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>)` Returns the value associated with the given key, or`null`if:                                                                                                                                                                                                                                  |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                           | `@`[ReplaceWith](https://developer.android.com/reference/kotlin/androidx/annotation/ReplaceWith)`(expression = "bundle.putBinder(key, binder)")` ~~[putBinder](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#putBinder(android.os.Bundle,java.lang.String,android.os.IBinder))~~`(bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)`, key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?, binder: `[IBinder](https://developer.android.com/reference/android/os/IBinder.html)`?)` **This function is deprecated.** Use[putBinder](https://developer.android.com/reference/android/os/Bundle.html#putBinder(java.lang.String, android.os.IBinder))directly. <br /> |

## Public functions

### getBinder

Added in[1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)  
Deprecated in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
@ReplaceWith(expression = "bundle.getBinder(key)")
java-static fun [getBinder](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#getBinder(android.os.Bundle,java.lang.String))(bundle: Bundle, key: String?): IBinder?
```
| **This function is deprecated.**   
|
| Use[getBinder](https://developer.android.com/reference/android/os/Bundle.html#getBinder(java.lang.String))directly.

A convenience method to handle getting an[IBinder](https://developer.android.com/reference/android/os/IBinder.html)inside a[Bundle](https://developer.android.com/reference/android/os/Bundle.html)for all Android versions.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)          | The bundle to get the[IBinder](https://developer.android.com/reference/android/os/IBinder.html).            |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The key to use while getting the[IBinder](https://developer.android.com/reference/android/os/IBinder.html). |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| [IBinder](https://developer.android.com/reference/android/os/IBinder.html)`?` | The[IBinder](https://developer.android.com/reference/android/os/IBinder.html)that was obtained. |

### getParcelable

Added in[1.10.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/android/os/Bundle.html#setClassLoader(java.lang.ClassLoader))with the proper[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)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](https://developer.android.com/reference/android/os/Bundle.html)              | The bundle to retrieve from.    |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | a String, or`null`              |
| `clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>`        | The type of the object expected |

| Returns |
|---------|------------------------------|
| `T?`    | a Parcelable value, or`null` |

### getParcelableArray

Added in[1.10.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/android/os/Bundle.html#setClassLoader(java.lang.ClassLoader))with the proper[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)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](https://developer.android.com/reference/android/os/Bundle.html)                                                                                        | The bundle to retrieve from.                                                    |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                           | a String, or`null`                                                              |
| `clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<`[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`!>` | The type of the items inside the array. This is only verified when unparceling. |

|                                                                                 Returns                                                                                 |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| [Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<`[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`!>?` | a Parcelable\[\] value, or`null` |

### getParcelableArrayList

Added in[1.10.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/android/os/Bundle.html#setClassLoader(java.lang.ClassLoader))with the proper[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)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](https://developer.android.com/reference/android/os/Bundle.html)              | The bundle to retrieve from.                                                         |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | a String, or`null`                                                                   |
| `clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>`        | The type of the items inside the array list. This is only verified when unparceling. |

|                                       Returns                                        |
|--------------------------------------------------------------------------------------|-----------------------|
| [ArrayList](https://developer.android.com/reference/java/util/ArrayList.html)`<T!>?` | an ArrayListvalue, or |

### getSerializable

Added in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/android/os/Bundle.html)              | The bundle to retrieve from.    |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | a String, or`null`              |
| `clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>`        | The type of the object expected |

| Returns |
|---------|--------------------------------|
| `T?`    | a Serializable value, or`null` |

### getSparseParcelableArray

Added in[1.10.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/reference/android/os/Bundle.html)              | The bundle to retrieve from.                                                           |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | a String, or null                                                                      |
| `clazz: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>`        | The type of the items inside the sparse array. This is only verified when unparceling. |

|                                           Returns                                           |
|---------------------------------------------------------------------------------------------|------------------------------------|
| [SparseArray](https://developer.android.com/reference/android/util/SparseArray.html)`<T!>?` | a SparseArray of T values, or null |

### putBinder

Added in[1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)  
Deprecated in[1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)  

```
@ReplaceWith(expression = "bundle.putBinder(key, binder)")
java-static fun [putBinder](https://developer.android.com/reference/kotlin/androidx/core/os/BundleCompat#putBinder(android.os.Bundle,java.lang.String,android.os.IBinder))(bundle: Bundle, key: String?, binder: IBinder?): Unit
```
| **This function is deprecated.**   
|
| Use[putBinder](https://developer.android.com/reference/android/os/Bundle.html#putBinder(java.lang.String, android.os.IBinder))directly.

A convenience method to handle putting an[IBinder](https://developer.android.com/reference/android/os/IBinder.html)inside a[Bundle](https://developer.android.com/reference/android/os/Bundle.html)for all Android versions.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| `bundle: `[Bundle](https://developer.android.com/reference/android/os/Bundle.html)          | The bundle to insert the[IBinder](https://developer.android.com/reference/android/os/IBinder.html).         |
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?` | The key to use while putting the[IBinder](https://developer.android.com/reference/android/os/IBinder.html). |
| `binder: `[IBinder](https://developer.android.com/reference/android/os/IBinder.html)`?`     | The[IBinder](https://developer.android.com/reference/android/os/IBinder.html)to put.                        |