ParcelCompat
public final class ParcelCompat
Helper for accessing features in Parcel.
Summary
Public methods |
|
|---|---|
static @Nullable Object[] |
Same as |
static @Nullable ArrayList<T> |
<T> readArrayList(Same as |
static boolean |
readBoolean(@NonNull Parcel in)Read a boolean value from the parcel at the current |
static @Nullable HashMap<K, V> |
<K, V> readHashMap(Same as |
static void |
<T> readList(Same as |
static void |
<K, V> readMap(Same as |
static @Nullable T |
<T extends Parcelable> readParcelable(Same as |
static @Nullable T[] |
<T> This method is deprecated. This method incurs a performance penalty on SDK 33 and below. |
static @Nullable Parcelable[] |
<T> readParcelableArrayTyped(Same as |
static @Nullable Parcelable.Creator<T> |
@RequiresApi(value = 30)Same as |
static @NonNull List<T> |
@RequiresApi(api = Build.VERSION_CODES.Q)Same as |
static @Nullable T |
<T extends Serializable> readSerializable(Same as |
static @Nullable SparseArray<T> |
<T> readSparseArray(Same as |
static void |
writeBoolean(@NonNull Parcel out, boolean value)Write a boolean value into the parcel at the current f |
Public methods
readArray
public static @Nullable Object[] <T> readArray(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
public static @Nullable ArrayList<T> <T> readArrayList(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
public static boolean readBoolean(@NonNull Parcel in)
Read a boolean value from the parcel at the current dataPosition.
readHashMap
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 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
public static void <T> readList(
@NonNull Parcel in,
@NonNull List<T> outVal,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
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 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
public static @Nullable T <T extends Parcelable> readParcelable(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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. |
public static @Nullable T[] <T>readParcelableArray(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
public static @Nullable Parcelable[] <T> readParcelableArrayTyped(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
@RequiresApi(value = 30)
public static @Nullable Parcelable.Creator<T> <T> readParcelableCreator(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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 |
readParcelableList
@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 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
public static @Nullable T <T extends Serializable> readSerializable(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
public static @Nullable SparseArray<T> <T> readSparseArray(
@NonNull Parcel in,
@Nullable ClassLoader loader,
@NonNull Class<T> 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
public static void writeBoolean(@NonNull Parcel out, boolean value)
Write a boolean value into the parcel at the current fdataPosition, growing dataCapacity if needed.