# ParcelCompat

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

*** ** * ** ***


```
public final class ParcelCompat
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html Object[]` | `<T> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readArray(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `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/ParcelCompat#readArrayList(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<? extends T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readArrayList(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `static boolean` | `https://developer.android.com/reference/androidx/core/os/ParcelCompat#readBoolean(android.os.Parcel)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in)` Read a boolean value from the parcel at the current `https://developer.android.com/reference/android/os/Parcel.html#dataPosition()`. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/HashMap.html<K, V>` | `<K, V> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readHashMap(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<? extends K>,java.lang.Class<? extends V>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<K> clazzKey, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<V> clazzValue )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readHashMap(java.lang.ClassLoader)` but accepts `clazzKey` and `clazzValue` parameter as the types required for each key and value pair. |
| `static void` | `<T> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readList(android.os.Parcel,java.util.List<? super T>,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<T> outVal, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readList(java.util.List, java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `static void` | `<K, V> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readMap(android.os.Parcel,java.util.Map<? super K,? super V>,java.lang.ClassLoader,java.lang.Class<K>,java.lang.Class<V>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Map.html<K, V> outVal, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<K> clazzKey, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<V> clazzValue )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readMap(java.util.Map, java.lang.ClassLoader)` but accepts `clazzKey` and `clazzValue` parameter as the types required for each key and value pair. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T` | `<T extends https://developer.android.com/reference/android/os/Parcelable.html> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelable(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelable(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html T[]` | `<T> [readParcelableArray](https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelableArray(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` **This method is deprecated.** This method incurs a performance penalty on SDK 33 and below. <br /> |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html Parcelable[]` | `<T> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelableArrayTyped(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/os/Parcelable.Creator.html<T>` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 30) <T> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelableCreator(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableCreator(java.lang.ClassLoader)` but accepts `clazz` parameter as the required type. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<T>` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(api = https://developer.android.com/reference/android/os/Build.VERSION_CODES.html#Q) <T> https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelableList(android.os.Parcel,java.util.List<T>,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<T> list, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html cl, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableList(java.util.List&lt;T&gt;, java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `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/ParcelCompat#readSerializable(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readSerializable()` but accepts `loader` parameter as the primary classLoader for resolving the Serializable class; and `clazz` parameter as the required type. |
| `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/ParcelCompat#readSparseArray(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<? extends T>)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html in, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/ClassLoader.html loader, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Class.html<T> clazz )` Same as `https://developer.android.com/reference/android/os/Parcel.html#readSparseArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. |
| `static void` | `https://developer.android.com/reference/androidx/core/os/ParcelCompat#writeBoolean(android.os.Parcel,boolean)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/os/Parcel.html out, boolean value)` Write a boolean value into the parcel at the current f`https://developer.android.com/reference/android/os/Parcel.html#dataPosition()`, growing `https://developer.android.com/reference/android/os/Parcel.html#dataCapacity()` if needed. |

## Public methods

### readArray

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

```
public static @Nullable Object[] <T> readArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the array elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readArrayList

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

```
public static @Nullable ArrayList<T> <T> readArrayList(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readArrayList(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the list elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readBoolean

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

```
public static boolean readBoolean(@NonNull Parcel in)
```

Read a boolean value from the parcel at the current `https://developer.android.com/reference/android/os/Parcel.html#dataPosition()`.

### readHashMap

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

```
public static @Nullable HashMap<K, V> <K, V> readHashMap(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<K> clazzKey,
    @NonNull Class<V> clazzValue
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readHashMap(java.lang.ClassLoader)` but accepts `clazzKey` and `clazzValue` parameter as the types required for each key and value pair. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the map entries' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | if the item to be deserialized is not an instance of that class or any of its children class. |

### readList

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

```
public static void <T> readList(
    @NonNull Parcel in,
    @NonNull List<T> outVal,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readList(java.util.List, java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the list elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readMap

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

```
public static void <K, V> readMap(
    @NonNull Parcel in,
    @NonNull Map<K, V> outVal,
    @Nullable ClassLoader loader,
    @NonNull Class<K> clazzKey,
    @NonNull Class<V> clazzValue
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readMap(java.util.Map, java.lang.ClassLoader)` but accepts `clazzKey` and `clazzValue` parameter as the types required for each key and value pair. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the map entries' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | If the item to be deserialized is not an instance of that class or any of its children class. |

### readParcelable

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

```
public static @Nullable T <T extends Parcelable> readParcelable(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelable(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

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

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readParcelableArray

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

```
public static @Nullable T[] <T> [readParcelableArray](https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelableArray(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>))(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> This method incurs a performance penalty on SDK 33 and below. Use `https://developer.android.com/reference/androidx/core/os/ParcelCompat#readParcelableArrayTyped(android.os.Parcel,java.lang.ClassLoader,java.lang.Class<T>)` instead.

Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the array elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readParcelableArrayTyped

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

```
public static @Nullable Parcelable[] <T> readParcelableArrayTyped(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the array elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readParcelableCreator

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

```
@RequiresApi(value = 30)
public static @Nullable Parcelable.Creator<T> <T> readParcelableCreator(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableCreator(java.lang.ClassLoader)` but accepts `clazz` parameter as the required type. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the creator's type.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there there was an error trying to read the `https://developer.android.com/reference/android/os/Parcelable.Creator.html`. |

### readParcelableList

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

```
@RequiresApi(api = Build.VERSION_CODES.Q)
public static @NonNull List<T> <T> readParcelableList(
    @NonNull Parcel in,
    @NonNull List<T> list,
    @Nullable ClassLoader cl,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readParcelableList(java.util.List&lt;T&gt;, java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the list elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### readSerializable

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

```
public static @Nullable T <T extends Serializable> readSerializable(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readSerializable()` but accepts `loader` parameter as the primary classLoader for resolving the Serializable class; and `clazz` parameter as the required type. Compatibility behavior:

- SDK 33 and later, this method matches platform behavior.
- SDK 32 and below, this method will not check the item's type.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children class or there there was an error deserializing the object. |

### readSparseArray

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

```
public static @Nullable SparseArray<T> <T> readSparseArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class<T> clazz
)
```

Same as `https://developer.android.com/reference/android/os/Parcel.html#readSparseArray(java.lang.ClassLoader)` but accepts `clazz` parameter as the type required for each item. Compatibility behavior:

- SDK 34 and later, this method matches platform behavior.
- SDK 33 and below, this method will not check the array elements' types.

| Throws |
|---|---|
| `https://developer.android.com/reference/android/os/BadParcelableException.html` | Throws BadParcelableException if the item to be deserialized is not an instance of that class or any of its children classes or there was an error trying to instantiate an element. |

### writeBoolean

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

```
public static void writeBoolean(@NonNull Parcel out, boolean value)
```

Write a boolean value into the parcel at the current f`https://developer.android.com/reference/android/os/Parcel.html#dataPosition()`, growing `https://developer.android.com/reference/android/os/Parcel.html#dataCapacity()` if needed.