# 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)

*** ** * ** ***


```
public final class BundleCompat
```

<br />

*** ** * ** ***

Helper for accessing features in `https://developer.android.com/reference/android/os/Bundle.html`.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/IBinder.html` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "bundle.getBinder(key)") [getBinder](https://developer.android.com/reference/androidx/core/os/BundleCompat#getBinder(android.os.Bundle,java.lang.String))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key)` **This method is deprecated.** Use `https://developer.android.com/reference/android/os/Bundle.html#getBinder(java.lang.String)` directly. <br /> |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | `<T> https://developer.android.com/reference/androidx/core/os/BundleCompat#getParcelable(android.os.Bundle,java.lang.String,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Returns the value associated with the given key or `null` if: |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html Parcelable[]` | `https://developer.android.com/reference/androidx/core/os/BundleCompat#getParcelableArray(android.os.Bundle,java.lang.String,java.lang.Class<? extends android.os.Parcelable>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/android/os/Parcelable.html> clazz )` Returns the value associated with the given key, or `null` if: |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/ArrayList.html<T>` | `<T> https://developer.android.com/reference/androidx/core/os/BundleCompat#getParcelableArrayList(android.os.Bundle,java.lang.String,java.lang.Class<? extends T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Returns the value associated with the given key, or `null` if: |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | `<T extends https://developer.android.com/reference/java/io/Serializable.html> https://developer.android.com/reference/androidx/core/os/BundleCompat#getSerializable(android.os.Bundle,java.lang.String,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Returns the value associated with the given key or `null` if: |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/util/SparseArray.html<T>` | `<T> https://developer.android.com/reference/androidx/core/os/BundleCompat#getSparseParcelableArray(android.os.Bundle,java.lang.String,java.lang.Class<? extends T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Returns the value associated with the given key, or `null` if: |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "bundle.putBinder(key, binder)") [putBinder](https://developer.android.com/reference/androidx/core/os/BundleCompat#putBinder(android.os.Bundle,java.lang.String,android.os.IBinder))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/IBinder.html binder )` **This method is deprecated.** Use `https://developer.android.com/reference/android/os/Bundle.html#putBinder(java.lang.String, android.os.IBinder)` directly. <br /> |

## Public methods

### 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)")
public static @Nullable IBinder [getBinder](https://developer.android.com/reference/androidx/core/os/BundleCompat#getBinder(android.os.Bundle,java.lang.String))(@NonNull Bundle bundle, @Nullable String key)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/os/Bundle.html#getBinder(java.lang.String)` directly.

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle` | The bundle to get the `https://developer.android.com/reference/android/os/IBinder.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | The key to use while getting the `https://developer.android.com/reference/android/os/IBinder.html`. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/IBinder.html` | The `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)

```
public static @Nullable T <T> getParcelable(
    @NonNull Bundle in,
    @Nullable String key,
    @NonNull 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 `https://developer.android.com/reference/android/os/Bundle.html#setClassLoader(java.lang.ClassLoader)` with the proper `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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in` | The bundle to retrieve from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | a String, or `null` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz` | The type of the object expected |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | a Parcelable value, or `null` |

### getParcelableArray

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

```
public static @Nullable Parcelable[] getParcelableArray(
    @NonNull Bundle in,
    @Nullable String key,
    @NonNull Class<Parcelable> 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 `https://developer.android.com/reference/android/os/Bundle.html#setClassLoader(java.lang.ClassLoader)` with the proper `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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in` | The bundle to retrieve from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | a String, or `null` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/android/os/Parcelable.html> clazz` | The type of the items inside the array. This is only verified when unparceling. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html Parcelable[]` | a Parcelable\[\] value, or `null` |

### getParcelableArrayList

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

```
public static @Nullable ArrayList<T> <T> getParcelableArrayList(
    @NonNull Bundle in,
    @Nullable String key,
    @NonNull 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 `https://developer.android.com/reference/android/os/Bundle.html#setClassLoader(java.lang.ClassLoader)` with the proper `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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in` | The bundle to retrieve from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | a String, or `null` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz` | The type of the items inside the array list. This is only verified when unparceling. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html 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)

```
public static @Nullable T <T extends Serializable> getSerializable(
    @NonNull Bundle in,
    @Nullable String key,
    @NonNull 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`.

Compatibility behavior:

<!-- -->

- SDK 34 and above, this method matches platform behavior.
- SDK 33 and below, the object type is checked after deserialization.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in` | The bundle to retrieve from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | a String, or `null` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz` | The type of the object expected |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | a Serializable value, or `null` |

### getSparseParcelableArray

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

```
public static @Nullable SparseArray<T> <T> getSparseParcelableArray(
    @NonNull Bundle in,
    @Nullable String key,
    @NonNull 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`.

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html in` | The bundle to retrieve from. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | a String, or null |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz` | The type of the items inside the sparse array. This is only verified when unparceling. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html 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)")
public static void [putBinder](https://developer.android.com/reference/androidx/core/os/BundleCompat#putBinder(android.os.Bundle,java.lang.String,android.os.IBinder))(
    @NonNull Bundle bundle,
    @Nullable String key,
    @Nullable IBinder binder
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/os/Bundle.html#putBinder(java.lang.String, android.os.IBinder)` directly.

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

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Bundle.html bundle` | The bundle to insert the `https://developer.android.com/reference/android/os/IBinder.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html key` | The key to use while putting the `https://developer.android.com/reference/android/os/IBinder.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/IBinder.html binder` | The `https://developer.android.com/reference/android/os/IBinder.html` to put. |