ParcelCompat

Added in 1.1.0

public final class ParcelCompat

Helper for accessing features in Parcel.

Summary

Public methods

static @Nullable Object[]
readArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readArray but accepts clazz parameter as the type required for each item.

static @Nullable ArrayList
readArrayList(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readArrayList but accepts clazz parameter as the type required for each item.

static boolean

Read a boolean value from the parcel at the current dataPosition.

static @Nullable HashMap
readHashMap(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazzKey,
    @NonNull Class clazzValue
)

Same as readHashMap but accepts clazzKey and clazzValue parameter as the types required for each key and value pair.

static void
readList(
    @NonNull Parcel in,
    @NonNull List outVal,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readList but accepts clazz parameter as the type required for each item.

static void
readMap(
    @NonNull Parcel in,
    @NonNull Map outVal,
    @Nullable ClassLoader loader,
    @NonNull Class clazzKey,
    @NonNull Class clazzValue
)

Same as readMap but accepts clazzKey and clazzValue parameter as the types required for each key and value pair.

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

Same as readParcelable but accepts clazz parameter as the type required for each item.

static @Nullable T[]
readParcelableArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

This method is deprecated.

This method incurs a performance penalty on SDK 33 and below.

static @Nullable Parcelable[]
readParcelableArrayTyped(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readParcelableArray but accepts clazz parameter as the type required for each item.

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

Same as readParcelableCreator but accepts clazz parameter as the required type.

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

Same as readParcelableList but accepts clazz parameter as the type required for each item.

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

Same as readSerializable but accepts loader parameter as the primary classLoader for resolving the Serializable class; and clazz parameter as the required type.

static @Nullable SparseArray
readSparseArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readSparseArray but accepts clazz parameter as the type required for each item.

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

Write a boolean value into the parcel at the current fdataPosition, growing dataCapacity if needed.

Public methods

readArray

Added in 1.9.0
public static @Nullable Object[]  readArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readArray 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
android.os.BadParcelableException

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
public static @Nullable ArrayList  readArrayList(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readArrayList 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
android.os.BadParcelableException

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
public static boolean readBoolean(@NonNull Parcel in)

Read a boolean value from the parcel at the current dataPosition.

readHashMap

Added in 1.9.0
public static @Nullable HashMap  readHashMap(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazzKey,
    @NonNull Class clazzValue
)

Same as readHashMap 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
android.os.BadParcelableException

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
public static void  readList(
    @NonNull Parcel in,
    @NonNull List outVal,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readList 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
android.os.BadParcelableException

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
public static void  readMap(
    @NonNull Parcel in,
    @NonNull Map outVal,
    @Nullable ClassLoader loader,
    @NonNull Class clazzKey,
    @NonNull Class clazzValue
)

Same as readMap 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
android.os.BadParcelableException

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
public static @NullableParcelable> readParcelable(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readParcelable 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
android.os.BadParcelableException

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
Deprecated in 1.10.0
public static @Nullable T[]  readParcelableArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readParcelableArray 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
android.os.BadParcelableException

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
public static @Nullable Parcelable[]  readParcelableArrayTyped(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readParcelableArray 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
android.os.BadParcelableException

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
@RequiresApi(value = 30)
public static @Nullable Parcelable.Creator  readParcelableCreator(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readParcelableCreator 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
android.os.BadParcelableException

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 Parcelable.Creator.

readParcelableList

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

Same as readParcelableList 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
android.os.BadParcelableException

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
public static @NullableSerializable> readSerializable(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as 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
android.os.BadParcelableException

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
public static @Nullable SparseArray  readSparseArray(
    @NonNull Parcel in,
    @Nullable ClassLoader loader,
    @NonNull Class clazz
)

Same as readSparseArray 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
android.os.BadParcelableException

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
public static void writeBoolean(@NonNull Parcel out, boolean value)

Write a boolean value into the parcel at the current fdataPosition, growing dataCapacity if needed.