Google is committed to advancing racial equity for Black communities. See how.
Added in API level 1

Parcel

class Parcel
kotlin.Any
   ↳ android.os.Parcel

Container for a message (data and object references) that can be sent through an IBinder. A Parcel can contain both flattened data that will be unflattened on the other side of the IPC (using the various methods here for writing specific types, or the general Parcelable interface), and references to live IBinder objects that will result in the other side receiving a proxy IBinder connected with the original IBinder in the Parcel.

Parcel is not a general-purpose serialization mechanism. This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport. As such, it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

The bulk of the Parcel API revolves around reading and writing data of various types. There are six major classes of such functions available.

Primitives

The most basic data functions are for writing and reading primitive data types: writeByte, readByte, writeDouble, readDouble, writeFloat, readFloat, writeInt, readInt, writeLong, readLong, writeString, readString. Most other data operations are built on top of these. The given data is written and read using the endianess of the host CPU.

Primitive Arrays

There are a variety of methods for reading and writing raw arrays of primitive objects, which generally result in writing a 4-byte length followed by the primitive data items. The methods for reading can either read the data into an existing array, or create and return a new array. These available types are:

Parcelables

The Parcelable protocol provides an extremely efficient (but low-level) protocol for objects to write and read themselves from Parcels. You can use the direct methods writeParcelable(android.os.Parcelable,int) and readParcelable(java.lang.ClassLoader) or writeParcelableArray and readParcelableArray(java.lang.ClassLoader) to write or read. These methods write both the class type and its data to the Parcel, allowing that class to be reconstructed from the appropriate class loader when later reading.

There are also some methods that provide a more efficient way to work with Parcelables: writeTypedObject, writeTypedArray, writeTypedList, readTypedObject, createTypedArray and createTypedArrayList. These methods do not write the class information of the original object: instead, the caller of the read function must know what type to expect and pass in the appropriate Parcelable.Creator instead to properly construct the new object and read its data. (To more efficient write and read a single Parcelable object that is not null, you can directly call Parcelable#writeToParcel and Parcelable.Creator#createFromParcel yourself.)

Bundles

A special type-safe container, called Bundle, is available for key/value maps of heterogeneous values. This has many optimizations for improved performance when reading and writing data, and its type-safe API avoids difficult to debug type errors when finally marshalling the data contents into a Parcel. The methods to use are writeBundle(android.os.Bundle), readBundle(), and readBundle(java.lang.ClassLoader).

Active Objects

An unusual feature of Parcel is the ability to read and write active objects. For these objects the actual contents of the object is not written, rather a special token referencing the object is written. When reading the object back from the Parcel, you do not get a new instance of the object, but rather a handle that operates on the exact same object that was originally written. There are two forms of active objects available.

Binder objects are a core facility of Android's general cross-process communication system. The IBinder interface describes an abstract protocol with a Binder object. Any such interface can be written in to a Parcel, and upon reading you will receive either the original object implementing that interface or a special proxy implementation that communicates calls back to the original object. The methods to use are writeStrongBinder(android.os.IBinder), writeStrongInterface(android.os.IInterface), readStrongBinder(), writeBinderArray(android.os.IBinder[]), readBinderArray(android.os.IBinder[]), createBinderArray(), writeBinderList(java.util.List), readBinderList(java.util.List), createBinderArrayList().

FileDescriptor objects, representing raw Linux file descriptor identifiers, can be written and ParcelFileDescriptor objects returned to operate on the original file descriptor. The returned file descriptor is a dup of the original file descriptor: the object and fd is different, but operating on the same underlying file stream, with the same position, etc. The methods to use are writeFileDescriptor(java.io.FileDescriptor), readFileDescriptor().

Untyped Containers

A final class of methods are for writing and reading standard Java containers of arbitrary types. These all revolve around the writeValue(java.lang.Object) and readValue(java.lang.ClassLoader) methods which define the types of objects allowed. The container methods are writeArray(java.lang.Object[]), readArray(java.lang.ClassLoader), writeList(java.util.List), readList(java.util.List,java.lang.ClassLoader), readArrayList(java.lang.ClassLoader), writeMap(java.util.Map), readMap(java.util.Map,java.lang.ClassLoader), writeSparseArray(android.util.SparseArray), readSparseArray(java.lang.ClassLoader).

Summary

Public methods
Unit
appendFrom(parcel: Parcel!, offset: Int, length: Int)

Array<IBinder!>?

ArrayList<IBinder!>?

Read and return a new ArrayList containing IBinder objects from the parcel that was written with writeBinderList at the current dataPosition().

BooleanArray?

ByteArray?

Read and return a byte[] object from the parcel.

CharArray?

DoubleArray?

FloatArray?

IntArray?

LongArray?

Array<String!>?

ArrayList<String!>?

Read and return a new ArrayList containing String objects from the parcel that was written with writeStringList at the current dataPosition().

Array<T>?

Read and return a new array containing a particular object type from the parcel at the current dataPosition().

ArrayList<T>?

Read and return a new ArrayList containing a particular object type from the parcel that was written with writeTypedList at the current dataPosition().

ArrayMap<String!, T>?

Read into a new ArrayMap with string keys items containing a particular object type that were written with writeTypedArrayMap(android.util.ArrayMap,int) at the current dataPosition().

SparseArray<T>?

Read into a new SparseArray items containing a particular object type that were written with writeTypedSparseArray(android.util.SparseArray,int) at the current dataPosition().

Int

Returns the amount of data remaining to be read from the parcel.

Int

Returns the total amount of space in the parcel.

Int

Returns the current position in the parcel data.

Int

Returns the total amount of data contained in the parcel.

Unit
enforceInterface(interfaceName: String!)

Boolean

Report whether the parcel contains any marshalled file descriptors.

ByteArray!

Returns the raw bytes of the parcel.

static Parcel

Retrieve a new Parcel object from the pool.

Array<Any!>?

Read and return a new Object array from the parcel at the current dataPosition().

ArrayList<Any!>?

Read and return a new ArrayList object from the parcel at the current dataPosition().

Unit

Unit

Read into the given List items IBinder objects that were written with writeBinderList at the current dataPosition().

Boolean

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

Unit

Bundle?

Read and return a new Bundle object from the parcel at the current dataPosition().

Bundle?

Read and return a new Bundle object from the parcel at the current dataPosition(), using the given class loader to initialize the class loader of the Bundle for later retrieval of Parcelable objects.

Byte

Read a byte value from the parcel at the current dataPosition().

Unit

Read a byte[] object from the parcel and copy it into the given byte array.

Unit

Double

Read a double precision floating point value from the parcel at the current dataPosition().

Unit

Unit

Special function for reading an exception result from the header of a parcel, to be used after receiving the result of a transaction.

Unit
readException(code: Int, msg: String!)

Throw an exception with the given message.

ParcelFileDescriptor!

Read a FileDescriptor from the parcel at the current dataPosition().

Float

Read a floating point value from the parcel at the current dataPosition().

Unit

HashMap<Any!, Any!>?

Please use readBundle(java.lang.ClassLoader) instead (whose data must have been written with writeBundle.

Int

Read an integer value from the parcel at the current dataPosition().

Unit

Unit
readList(outVal: MutableList<Any?>, loader: ClassLoader?)

Read into an existing List object from the parcel at the current dataPosition(), using the given class loader to load any enclosed Parcelables.

Long

Read a long integer value from the parcel at the current dataPosition().

Unit

Unit
readMap(outVal: MutableMap<Any?, Any?>, loader: ClassLoader?)

Please use readBundle(java.lang.ClassLoader) instead (whose data must have been written with writeBundle.

T?

Read and return a new Parcelable from the parcel.

Array<Parcelable!>?

Read and return a new Parcelable array from the parcel.

Parcelable.Creator<*>?

Read and return a Parcelable.

MutableList<T>

Read the list of Parcelable objects at the current data position into the given list.

PersistableBundle?

Read and return a new Bundle object from the parcel at the current dataPosition().

PersistableBundle?

Read and return a new Bundle object from the parcel at the current dataPosition(), using the given class loader to initialize the class loader of the Bundle for later retrieval of Parcelable objects.

Serializable?

Read and return a new Serializable object from the parcel.

Size

Read a Size from the parcel at the current dataPosition().

SizeF

Read a SizeF from the parcel at the current dataPosition().

SparseArray<T>?

Read and return a new SparseArray object from the parcel at the current dataPosition().

SparseBooleanArray?

Read and return a new SparseBooleanArray object from the parcel at the current dataPosition().

String?

Read a string value from the parcel at the current dataPosition().

Unit

Unit

Read into the given List items String objects that were written with writeStringList at the current dataPosition().

IBinder!

Read an object from the parcel at the current dataPosition().

Unit

Unit

Read into the given List items containing a particular object type that were written with writeTypedList at the current dataPosition().

T?

Read and return a typed Parcelable object from a parcel.

Any?

Read a typed object from a parcel.

Unit

Put a Parcel object back into the pool.

Unit

Change the capacity (current available space) of the parcel.

Unit

Move the current read/write position in the parcel.

Unit

Change the amount of data in the parcel.

Unit
unmarshall(data: ByteArray, offset: Int, length: Int)

Set the bytes in data to be the raw bytes of this Parcel.

Unit
writeArray(val: Array<Any!>?)

Flatten an Object array into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit

Flatten a List containing IBinder objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed.

Unit

Write a boolean value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit

Flatten a Bundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Write a byte value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Write a byte array into the parcel at the current dataPosition, growing dataCapacity if needed.

Unit
writeByteArray(b: ByteArray?, offset: Int, len: Int)

Write a byte array into the parcel at the current dataPosition, growing dataCapacity if needed.

Unit

Unit

Write a double precision floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit

Special function for writing an exception result at the header of a parcel, to be used when returning an exception from a transaction.

Unit

Write a FileDescriptor into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Write a floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit
writeInt(val: Int)

Write an integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit
writeInterfaceToken(interfaceName: String!)

Store or read an IBinder interface token in the parcel at the current dataPosition.

Unit

Flatten a List into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Write a long integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit
writeMap(val: MutableMap<Any?, Any?>?)

Please use writeBundle instead.

Unit

Special function for writing information at the front of the Parcel indicating that no exception occurred.

Unit
writeParcelable(p: Parcelable?, parcelableFlags: Int)

Flatten the name of the class of the Parcelable and its contents into the parcel.

Unit
writeParcelableArray(value: Array<T>?, parcelableFlags: Int)

Write a heterogeneous array of Parcelable objects into the Parcel.

Unit

Flatten the name of the class of the Parcelable into this Parcel.

Unit
writeParcelableList(val: MutableList<T>?, flags: Int)

Flatten a List containing arbitrary Parcelable objects into this parcel at the current position.

Unit

Flatten a PersistableBundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Write a generic serializable object in to a Parcel.

Unit

Flatten a Size into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Flatten a SizeF into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Flatten a generic SparseArray into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit

Write a string value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Unit

Flatten a List containing String objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed.

Unit

Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit

Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Unit
writeTypedArray(val: Array<T>?, parcelableFlags: Int)

Flatten a homogeneous array containing a particular object type into the parcel, at the current dataPosition() and growing dataCapacity() if needed.

Unit
writeTypedArrayMap(val: ArrayMap<String!, T>?, parcelableFlags: Int)

Flatten an ArrayMap with string keys containing a particular object type into the parcel at the current dataPosition() and growing dataCapacity() if needed.

Unit

Flatten a List containing a particular object type into the parcel, at the current dataPosition() and growing dataCapacity() if needed.

Unit
writeTypedObject(val: T?, parcelableFlags: Int)

Flatten the Parcelable object into the parcel.

Unit
writeTypedSparseArray(val: SparseArray<T>?, parcelableFlags: Int)

Flatten a SparseArray containing a particular object type into the parcel at the current dataPosition() and growing dataCapacity() if needed.

Unit

Flatten a generic object in to a parcel.

Protected methods
Unit

Properties
static Parcelable.Creator<String!>!

Public methods

appendFrom

Added in API level 1
fun appendFrom(
    parcel: Parcel!,
    offset: Int,
    length: Int
): Unit

createBinderArray

Added in API level 1
fun createBinderArray(): Array<IBinder!>?
Return
Array<IBinder!>? This value may be null.

createBinderArrayList

Added in API level 1
fun createBinderArrayList(): ArrayList<IBinder!>?

Read and return a new ArrayList containing IBinder objects from the parcel that was written with writeBinderList at the current dataPosition(). Returns null if the previously written list object was null.

Return
ArrayList<IBinder!>? A newly created ArrayList containing strings with the same data as those that were previously written.

See Also

createBooleanArray

Added in API level 1
fun createBooleanArray(): BooleanArray?
Return
BooleanArray? This value may be null.

createByteArray

Added in API level 1
fun createByteArray(): ByteArray?

Read and return a byte[] object from the parcel.

Return
ByteArray? This value may be null.

createCharArray

Added in API level 1
fun createCharArray(): CharArray?
Return
CharArray? This value may be null.

createDoubleArray

Added in API level 1
fun createDoubleArray(): DoubleArray?
Return
DoubleArray? This value may be null.

createFloatArray

Added in API level 1
fun createFloatArray(): FloatArray?
Return
FloatArray? This value may be null.

createIntArray

Added in API level 1
fun createIntArray(): IntArray?
Return
IntArray? This value may be null.

createLongArray

Added in API level 1
fun createLongArray(): LongArray?
Return
LongArray? This value may be null.

createStringArray

Added in API level 1
fun createStringArray(): Array<String!>?
Return
Array<String!>? This value may be null.

createStringArrayList

Added in API level 1
fun createStringArrayList(): ArrayList<String!>?

Read and return a new ArrayList containing String objects from the parcel that was written with writeStringList at the current dataPosition(). Returns null if the previously written list object was null.

Return
ArrayList<String!>? A newly created ArrayList containing strings with the same data as those that were previously written.

See Also

createTypedArray

Added in API level 1
fun <T : Any!> createTypedArray(c: Parcelable.Creator<T>): Array<T>?

Read and return a new array containing a particular object type from the parcel at the current dataPosition(). Returns null if the previously written array was null. The array must have previously been written via writeTypedArray with the same object type.

Parameters
c Parcelable.Creator<T>: This value cannot be null.
Return
Array<T>? A newly created array containing objects with the same data as those that were previously written.

See Also

createTypedArrayList

Added in API level 1
fun <T : Any!> createTypedArrayList(c: Parcelable.Creator<T>): ArrayList<T>?

Read and return a new ArrayList containing a particular object type from the parcel that was written with writeTypedList at the current dataPosition(). Returns null if the previously written list object was null. The list must have previously been written via writeTypedList with the same object type.

Parameters
c Parcelable.Creator<T>: This value cannot be null.
Return
ArrayList<T>? A newly created ArrayList containing objects with the same data as those that were previously written.

See Also

createTypedArrayMap

Added in API level 29
fun <T : Parcelable!> createTypedArrayMap(creator: Parcelable.Creator<T>): ArrayMap<String!, T>?

Read into a new ArrayMap with string keys items containing a particular object type that were written with writeTypedArrayMap(android.util.ArrayMap,int) at the current dataPosition(). The list must have previously been written via writeTypedArrayMap(android.util.ArrayMap,int) with the same object type.

Parameters
creator Parcelable.Creator<T>: The creator to use when for instantiation. This value cannot be null.
Return
ArrayMap<String!, T>? A newly created ArrayMap containing objects with the same data as those that were previously written. This value may be null.

createTypedSparseArray

Added in API level 29
fun <T : Parcelable!> createTypedSparseArray(creator: Parcelable.Creator<T>): SparseArray<T>?

Read into a new SparseArray items containing a particular object type that were written with writeTypedSparseArray(android.util.SparseArray,int) at the current dataPosition(). The list must have previously been written via writeTypedSparseArray(android.util.SparseArray,int) with the same object type.

Parameters
creator Parcelable.Creator<T>: The creator to use when for instantiation. This value cannot be null.
Return
SparseArray<T>? A newly created SparseArray containing objects with the same data as those that were previously written. This value may be null.

dataAvail

Added in API level 1
fun dataAvail(): Int

Returns the amount of data remaining to be read from the parcel. That is, dataSize-dataPosition.

dataCapacity

Added in API level 1
fun dataCapacity(): Int

Returns the total amount of space in the parcel. This is always >= dataSize. The difference between it and dataSize() is the amount of room left until the parcel needs to re-allocate its data buffer.

dataPosition

Added in API level 1
fun dataPosition(): Int

Returns the current position in the parcel data. Never more than dataSize.

dataSize

Added in API level 1
fun dataSize(): Int

Returns the total amount of data contained in the parcel.

enforceInterface

Added in API level 1
fun enforceInterface(interfaceName: String!): Unit

hasFileDescriptors

Added in API level 1
fun hasFileDescriptors(): Boolean

Report whether the parcel contains any marshalled file descriptors.

marshall

Added in API level 1
fun marshall(): ByteArray!

Returns the raw bytes of the parcel.

The data you retrieve here must not be placed in any kind of persistent storage (on local disk, across a network, etc). For that, you should use standard serialization or another kind of general serialization mechanism. The Parcel marshalled representation is highly optimized for local IPC, and as such does not attempt to maintain compatibility with data created in different versions of the platform.

obtain

Added in API level 1
static fun obtain(): Parcel

Retrieve a new Parcel object from the pool.

Return
Parcel This value cannot be null.

readArray

Added in API level 1
fun readArray(loader: ClassLoader?): Array<Any!>?

Read and return a new Object array from the parcel at the current dataPosition(). Returns null if the previously written array was null. The given class loader will be used to load any enclosed Parcelables.

Parameters
loader ClassLoader?: This value may be null.

readArrayList

Added in API level 1
fun readArrayList(loader: ClassLoader?): ArrayList<Any!>?

Read and return a new ArrayList object from the parcel at the current dataPosition(). Returns null if the previously written list object was null. The given class loader will be used to load any enclosed Parcelables.

Parameters
loader ClassLoader?: This value may be null.

readBinderArray

Added in API level 1
fun readBinderArray(val: Array<IBinder!>): Unit
Parameters
val Array<IBinder!>: This value cannot be null.

readBinderList

Added in API level 1
fun readBinderList(list: MutableList<IBinder!>): Unit

Read into the given List items IBinder objects that were written with writeBinderList at the current dataPosition().

Parameters
list MutableList<IBinder!>: This value cannot be null.

See Also

readBoolean

Added in API level 29
fun readBoolean(): Boolean

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

readBooleanArray

Added in API level 1
fun readBooleanArray(val: BooleanArray): Unit
Parameters
val BooleanArray: This value cannot be null.

readBundle

Added in API level 1
fun readBundle(): Bundle?

Read and return a new Bundle object from the parcel at the current dataPosition(). Returns null if the previously written Bundle object was null.

readBundle

Added in API level 1
fun readBundle(loader: ClassLoader?): Bundle?

Read and return a new Bundle object from the parcel at the current dataPosition(), using the given class loader to initialize the class loader of the Bundle for later retrieval of Parcelable objects. Returns null if the previously written Bundle object was null.

Parameters
loader ClassLoader?: This value may be null.

readByte

Added in API level 1
fun readByte(): Byte

Read a byte value from the parcel at the current dataPosition().

readByteArray

Added in API level 1
fun readByteArray(val: ByteArray): Unit

Read a byte[] object from the parcel and copy it into the given byte array.

Parameters
val ByteArray: This value cannot be null.

readCharArray

Added in API level 1
fun readCharArray(val: CharArray): Unit
Parameters
val CharArray: This value cannot be null.

readDouble

Added in API level 1
fun readDouble(): Double

Read a double precision floating point value from the parcel at the current dataPosition().

readDoubleArray

Added in API level 1
fun readDoubleArray(val: DoubleArray): Unit
Parameters
val DoubleArray: This value cannot be null.

readException

Added in API level 1
fun readException(): Unit

Special function for reading an exception result from the header of a parcel, to be used after receiving the result of a transaction. This will throw the exception for you if it had been written to the Parcel, otherwise return and let you read the normal result data from the Parcel.

readException

Added in API level 1
fun readException(
    code: Int,
    msg: String!
): Unit

Throw an exception with the given message. Not intended for use outside the Parcel class.

Parameters
code Int: Used to determine which exception class to throw.
msg String!: The exception message.

readFileDescriptor

Added in API level 1
fun readFileDescriptor(): ParcelFileDescriptor!

Read a FileDescriptor from the parcel at the current dataPosition().

readFloat

Added in API level 1
fun readFloat(): Float

Read a floating point value from the parcel at the current dataPosition().

readFloatArray

Added in API level 1
fun readFloatArray(val: FloatArray): Unit
Parameters
val FloatArray: This value cannot be null.

readHashMap

Added in API level 1
fun readHashMap(loader: ClassLoader?): HashMap<Any!, Any!>?

Please use readBundle(java.lang.ClassLoader) instead (whose data must have been written with writeBundle. Read and return a new HashMap object from the parcel at the current dataPosition(), using the given class loader to load any enclosed Parcelables. Returns null if the previously written map object was null.

Parameters
loader ClassLoader?: This value may be null.

readInt

Added in API level 1
fun readInt(): Int

Read an integer value from the parcel at the current dataPosition().

readIntArray

Added in API level 1
fun readIntArray(val: IntArray): Unit
Parameters
val IntArray: This value cannot be null.

readList

Added in API level 1
fun readList(
    outVal: MutableList<Any?>,
    loader: ClassLoader?
): Unit

Read into an existing List object from the parcel at the current dataPosition(), using the given class loader to load any enclosed Parcelables. If it is null, the default class loader is used.

Parameters
outVal MutableList<Any?>: This value cannot be null.
loader ClassLoader?: This value may be null.

readLong

Added in API level 1
fun readLong(): Long

Read a long integer value from the parcel at the current dataPosition().

readLongArray

Added in API level 1
fun readLongArray(val: LongArray): Unit
Parameters
val LongArray: This value cannot be null.

readMap

Added in API level 1
fun readMap(
    outVal: MutableMap<Any?, Any?>,
    loader: ClassLoader?
): Unit

Please use readBundle(java.lang.ClassLoader) instead (whose data must have been written with writeBundle. Read into an existing Map object from the parcel at the current dataPosition().

Parameters
outVal MutableMap<Any?, Any?>: This value cannot be null.
loader ClassLoader?: This value may be null.

readParcelable

Added in API level 1
fun <T : Parcelable!> readParcelable(loader: ClassLoader?): T?

Read and return a new Parcelable from the parcel. The given class loader will be used to load any enclosed Parcelables. If it is null, the default class loader will be used.

Parameters
loader ClassLoader?: A ClassLoader from which to instantiate the Parcelable object, or null for the default class loader. This value may be null.
Return
T? Returns the newly created Parcelable, or null if a null object has been written.
Exceptions
android.os.BadParcelableException Throws BadParcelableException if there was an error trying to instantiate the Parcelable.

readParcelableArray

Added in API level 1
fun readParcelableArray(loader: ClassLoader?): Array<Parcelable!>?

Read and return a new Parcelable array from the parcel. The given class loader will be used to load any enclosed Parcelables.

Parameters
loader ClassLoader?: This value may be null.
Return
Array<Parcelable!>? the Parcelable array, or null if the array is null

readParcelableCreator

Added in API level 30
fun readParcelableCreator(loader: ClassLoader?): Parcelable.Creator<*>?

Read and return a Parcelable.Creator from the parcel. The given class loader will be used to load the Parcelable.Creator. If it is null, the default class loader will be used.

Parameters
loader ClassLoader?: A ClassLoader from which to instantiate the Parcelable.Creator object, or null for the default class loader. This value may be null.
Return
Parcelable.Creator<*>? the previously written Parcelable.Creator, or null if a null Creator was written.
Exceptions
android.os.BadParcelableException Throws BadParcelableException if there was an error trying to read the Parcelable.Creator.

readParcelableList

Added in API level 29
fun <T : Parcelable!> readParcelableList(
    list: MutableList<T>,
    cl: ClassLoader?
): MutableList<T>

Read the list of Parcelable objects at the current data position into the given list. The contents of the list are replaced. If the serialized list was null, list is cleared.

Parameters
list MutableList<T>: This value cannot be null.
cl ClassLoader?: This value may be null.

readPersistableBundle

Added in API level 21
fun readPersistableBundle(): PersistableBundle?

Read and return a new Bundle object from the parcel at the current dataPosition(). Returns null if the previously written Bundle object was null.

readPersistableBundle

Added in API level 21
fun readPersistableBundle(loader: ClassLoader?): PersistableBundle?

Read and return a new Bundle object from the parcel at the current dataPosition(), using the given class loader to initialize the class loader of the Bundle for later retrieval of Parcelable objects. Returns null if the previously written Bundle object was null.

Parameters
loader ClassLoader?: This value may be null.

readSerializable

Added in API level 1
fun readSerializable(): Serializable?

Read and return a new Serializable object from the parcel.

Return
Serializable? the Serializable object, or null if the Serializable name wasn't found in the parcel.

readSize

Added in API level 21
fun readSize(): Size

Read a Size from the parcel at the current dataPosition().

Return
Size This value cannot be null.

readSizeF

Added in API level 21
fun readSizeF(): SizeF

Read a SizeF from the parcel at the current dataPosition().

Return
SizeF This value cannot be null.

readSparseArray

Added in API level 1
fun <T : Any!> readSparseArray(loader: ClassLoader?): SparseArray<T>?

Read and return a new SparseArray object from the parcel at the current dataPosition(). Returns null if the previously written list object was null. The given class loader will be used to load any enclosed Parcelables.

Parameters
loader ClassLoader?: This value may be null.

readSparseBooleanArray

Added in API level 1
fun readSparseBooleanArray(): SparseBooleanArray?

Read and return a new SparseBooleanArray object from the parcel at the current dataPosition(). Returns null if the previously written list object was null.

readString

Added in API level 1
fun readString(): String?

Read a string value from the parcel at the current dataPosition().

Return
String? This value may be null.

readStringArray

Added in API level 1
fun readStringArray(val: Array<String!>): Unit
Parameters
val Array<String!>: This value cannot be null.

readStringList

Added in API level 1
fun readStringList(list: MutableList<String!>): Unit

Read into the given List items String objects that were written with writeStringList at the current dataPosition().

Parameters
list MutableList<String!>: This value cannot be null.

See Also

readStrongBinder

Added in API level 1
fun readStrongBinder(): IBinder!

Read an object from the parcel at the current dataPosition().

readTypedArray

Added in API level 1
fun <T : Any!> readTypedArray(
    val: Array<T>,
    c: Parcelable.Creator<T>
): Unit
Parameters
val Array<T>: This value cannot be null.
c Parcelable.Creator<T>: This value cannot be null.

readTypedList

Added in API level 1
fun <T : Any!> readTypedList(
    list: MutableList<T>,
    c: Parcelable.Creator<T>
): Unit

Read into the given List items containing a particular object type that were written with writeTypedList at the current dataPosition(). The list must have previously been written via writeTypedList with the same object type.

Parameters
list MutableList<T>: This value cannot be null.
c Parcelable.Creator<T>: This value cannot be null.
Return
Unit A newly created ArrayList containing objects with the same data as those that were previously written.

See Also

readTypedObject

Added in API level 23
fun <T : Any!> readTypedObject(c: Parcelable.Creator<T>): T?

Read and return a typed Parcelable object from a parcel. Returns null if the previous written object was null. The object must have previous been written via writeTypedObject with the same object type.

Parameters
c Parcelable.Creator<T>: This value cannot be null.
Return
T? A newly created object of the type that was previously written.

readValue

Added in API level 1
fun readValue(loader: ClassLoader?): Any?

Read a typed object from a parcel. The given class loader will be used to load any enclosed Parcelables. If it is null, the default class loader will be used.

Parameters
loader ClassLoader?: This value may be null.

recycle

Added in API level 1
fun recycle(): Unit

Put a Parcel object back into the pool. You must not touch the object after this call.

setDataCapacity

Added in API level 1
fun setDataCapacity(size: Int): Unit

Change the capacity (current available space) of the parcel.

Parameters
size Int: The new capacity of the parcel, in bytes. Can not be less than dataSize -- that is, you can not drop existing data with this method.

setDataPosition

Added in API level 1
fun setDataPosition(pos: Int): Unit

Move the current read/write position in the parcel.

Parameters
pos Int: New offset in the parcel; must be between 0 and dataSize.

setDataSize

Added in API level 1
fun setDataSize(size: Int): Unit

Change the amount of data in the parcel. Can be either smaller or larger than the current size. If larger than the current capacity, more memory will be allocated.

Parameters
size Int: The new number of bytes in the Parcel.

unmarshall

Added in API level 1
fun unmarshall(
    data: ByteArray,
    offset: Int,
    length: Int
): Unit

Set the bytes in data to be the raw bytes of this Parcel.

Parameters
data ByteArray: This value cannot be null.

writeArray

Added in API level 1
fun writeArray(val: Array<Any!>?): Unit

Flatten an Object array into the parcel at the current dataPosition(), growing dataCapacity() if needed. The array values are written using writeValue and must follow the specification there.

Parameters
val Array<Any!>?: This value may be null.

writeBinderArray

Added in API level 1
fun writeBinderArray(val: Array<IBinder!>?): Unit
Parameters
val Array<IBinder!>?: This value may be null.

writeBinderList

Added in API level 1
fun writeBinderList(val: MutableList<IBinder!>?): Unit

Flatten a List containing IBinder objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed. They can later be retrieved with createBinderArrayList or readBinderList.

Parameters
val MutableList<IBinder!>?: The list of strings to be written. This value may be null.

writeBoolean

Added in API level 29
fun writeBoolean(val: Boolean): Unit

Write a boolean value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Note: This method currently delegates to writeInt with a value of 1 or 0 for true or false, respectively, but may change in the future.

writeBooleanArray

Added in API level 1
fun writeBooleanArray(val: BooleanArray?): Unit
Parameters
val BooleanArray?: This value may be null.

writeBundle

Added in API level 1
fun writeBundle(val: Bundle?): Unit

Flatten a Bundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Parameters
val Bundle?: This value may be null.

writeByte

Added in API level 1
fun writeByte(val: Byte): Unit

Write a byte value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Note: This method currently delegates to writeInt but may change in the future.

writeByteArray

Added in API level 1
fun writeByteArray(b: ByteArray?): Unit

Write a byte array into the parcel at the current dataPosition, growing dataCapacity if needed.

Parameters
b ByteArray?: Bytes to place into the parcel. This value may be null.

writeByteArray

Added in API level 1
fun writeByteArray(
    b: ByteArray?,
    offset: Int,
    len: Int
): Unit

Write a byte array into the parcel at the current dataPosition, growing dataCapacity if needed.

Parameters
b ByteArray?: Bytes to place into the parcel. This value may be null.
offset Int: Index of first byte to be written.
len Int: Number of bytes to write.

writeCharArray

Added in API level 1
fun writeCharArray(val: CharArray?): Unit
Parameters
val CharArray?: This value may be null.

writeDouble

Added in API level 1
fun writeDouble(val: Double): Unit

Write a double precision floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

writeDoubleArray

Added in API level 1
fun writeDoubleArray(val: DoubleArray?): Unit
Parameters
val DoubleArray?: This value may be null.

writeException

Added in API level 1
fun writeException(e: Exception): Unit

Special function for writing an exception result at the header of a parcel, to be used when returning an exception from a transaction. Note that this currently only supports a few exception types; any other exception will be re-thrown by this function as a RuntimeException (to be caught by the system's last-resort exception handling when dispatching a transaction).

The supported exception types are:

Parameters
e Exception: The Exception to be written. This value cannot be null.

writeFileDescriptor

Added in API level 1
fun writeFileDescriptor(val: FileDescriptor): Unit

Write a FileDescriptor into the parcel at the current dataPosition(), growing dataCapacity() if needed.

The file descriptor will not be closed, which may result in file descriptor leaks when objects are returned from Binder calls. Use ParcelFileDescriptor#writeToParcel instead, which accepts contextual flags and will close the original file descriptor if Parcelable#PARCELABLE_WRITE_RETURN_VALUE is set.

Parameters
val FileDescriptor: This value cannot be null.

writeFloat

Added in API level 1
fun writeFloat(val: Float): Unit

Write a floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

writeFloatArray

Added in API level 1
fun writeFloatArray(val: FloatArray?): Unit
Parameters
val FloatArray?: This value may be null.

writeInt

Added in API level 1
fun writeInt(val: Int): Unit

Write an integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

writeIntArray

Added in API level 1
fun writeIntArray(val: IntArray?): Unit
Parameters
val IntArray?: This value may be null.

writeInterfaceToken

Added in API level 1
fun writeInterfaceToken(interfaceName: String!): Unit

Store or read an IBinder interface token in the parcel at the current dataPosition. This is used to validate that the marshalled transaction is intended for the target interface.

writeList

Added in API level 1
fun writeList(val: MutableList<Any?>?): Unit

Flatten a List into the parcel at the current dataPosition(), growing dataCapacity() if needed. The List values are written using writeValue and must follow the specification there.

Parameters
val MutableList<Any?>?: This value may be null.

writeLong

Added in API level 1
fun writeLong(val: Long): Unit

Write a long integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

writeLongArray

Added in API level 1
fun writeLongArray(val: LongArray?): Unit
Parameters
val LongArray?: This value may be null.

writeMap

Added in API level 1
fun writeMap(val: MutableMap<Any?, Any?>?): Unit

Please use writeBundle instead. Flattens a Map into the parcel at the current dataPosition(), growing dataCapacity() if needed. The Map keys must be String objects. The Map values are written using writeValue and must follow the specification there.

It is strongly recommended to use writeBundle instead of this method, since the Bundle class provides a type-safe API that allows you to avoid mysterious type errors at the point of marshalling.

Parameters
val MutableMap<Any?, Any?>?: This value may be null.

writeNoException

Added in API level 1
fun writeNoException(): Unit

Special function for writing information at the front of the Parcel indicating that no exception occurred.

writeParcelable

Added in API level 1
fun writeParcelable(
    p: Parcelable?,
    parcelableFlags: Int
): Unit

Flatten the name of the class of the Parcelable and its contents into the parcel.

Parameters
p Parcelable?: The Parcelable object to be written. This value may be null.
parcelableFlags Int: Contextual flags as per Parcelable#writeToParcel(Parcel, int).

writeParcelableArray

Added in API level 1
fun <T : Parcelable!> writeParcelableArray(
    value: Array<T>?,
    parcelableFlags: Int
): Unit

Write a heterogeneous array of Parcelable objects into the Parcel. Each object in the array is written along with its class name, so that the correct class can later be instantiated. As a result, this has significantly more overhead than writeTypedArray, but will correctly handle an array containing more than one type of object.

Parameters
value Array<T>?: The array of objects to be written. This value may be null.
parcelableFlags Int: Contextual flags as per Parcelable#writeToParcel(Parcel, int).

See Also

writeParcelableCreator

Added in API level 30
fun writeParcelableCreator(p: Parcelable): Unit

Flatten the name of the class of the Parcelable into this Parcel.

Parameters
p Parcelable: The Parcelable object to be written. This value cannot be null.

writeParcelableList

Added in API level 29
fun <T : Parcelable!> writeParcelableList(
    val: MutableList<T>?,
    flags: Int
): Unit

Flatten a List containing arbitrary Parcelable objects into this parcel at the current position. They can later be retrieved using readParcelableList(java.util.List,java.lang.ClassLoader) if required.

Parameters
val MutableList<T>?: This value may be null.

writePersistableBundle

Added in API level 21
fun writePersistableBundle(val: PersistableBundle?): Unit

Flatten a PersistableBundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Parameters
val PersistableBundle?: This value may be null.

writeSerializable

Added in API level 1
fun writeSerializable(s: Serializable?): Unit

Write a generic serializable object in to a Parcel. It is strongly recommended that this method be avoided, since the serialization overhead is extremely large, and this approach will be much slower than using the other approaches to writing data in to a Parcel.

Parameters
s Serializable?: This value may be null.

writeSize

Added in API level 21
fun writeSize(val: Size): Unit

Flatten a Size into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Parameters
val Size: This value cannot be null.

writeSizeF

Added in API level 21
fun writeSizeF(val: SizeF): Unit

Flatten a SizeF into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Parameters
val SizeF: This value cannot be null.

writeSparseArray

Added in API level 1
fun <T : Any!> writeSparseArray(val: SparseArray<T>?): Unit

Flatten a generic SparseArray into the parcel at the current dataPosition(), growing dataCapacity() if needed. The SparseArray values are written using writeValue and must follow the specification there.

Parameters
val SparseArray<T>?: This value may be null.

writeSparseBooleanArray

Added in API level 1
fun writeSparseBooleanArray(val: SparseBooleanArray?): Unit
Parameters
val SparseBooleanArray?: This value may be null.

writeString

Added in API level 1
fun writeString(val: String?): Unit

Write a string value into the parcel at the current dataPosition(), growing dataCapacity() if needed.

Parameters
val String?: This value may be null.

writeStringArray

Added in API level 1
fun writeStringArray(val: Array<String!>?): Unit
Parameters
val Array<String!>?: This value may be null.

writeStringList

Added in API level 1
fun writeStringList(val: MutableList<String!>?): Unit

Flatten a List containing String objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed. They can later be retrieved with createStringArrayList or readStringList.

Parameters
val MutableList<String!>?: The list of strings to be written. This value may be null.

writeStrongBinder

Added in API level 1
fun writeStrongBinder(val: IBinder!): Unit

Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.

writeStrongInterface

Added in API level 1
fun writeStrongInterface(val: IInterface!): Unit

Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.

writeTypedArray

Added in API level 1
fun <T : Parcelable!> writeTypedArray(
    val: Array<T>?,
    parcelableFlags: Int
): Unit

Flatten a homogeneous array containing a particular object type into the parcel, at the current dataPosition() and growing dataCapacity() if needed. The type of the objects in the array must be one that implements Parcelable. Unlike the writeParcelableArray method, however, only the raw data of the objects is written and not their type, so you must use readTypedArray with the correct corresponding Parcelable.Creator implementation to unmarshall them.

Parameters
val Array<T>?: The array of objects to be written. This value may be null.
parcelableFlags Int: Contextual flags as per Parcelable#writeToParcel(Parcel, int).

writeTypedArrayMap

Added in API level 29
fun <T : Parcelable!> writeTypedArrayMap(
    val: ArrayMap<String!, T>?,
    parcelableFlags: Int
): Unit

Flatten an ArrayMap with string keys containing a particular object type into the parcel at the current dataPosition() and growing dataCapacity() if needed. The type of the objects in the array must be one that implements Parcelable. Only the raw data of the objects is written and not their type, so you must use the corresponding createTypedArrayMap(android.os.Parcelable.Creator)

Parameters
val ArrayMap<String!, T>?: The map of objects to be written. This value may be null.
parcelableFlags Int: The parcelable flags to use.

writeTypedList

Added in API level 1
fun <T : Parcelable!> writeTypedList(val: MutableList<T>?): Unit

Flatten a List containing a particular object type into the parcel, at the current dataPosition() and growing dataCapacity() if needed. The type of the objects in the list must be one that implements Parcelable. Unlike the generic writeList() method, however, only the raw data of the objects is written and not their type, so you must use the corresponding readTypedList() to unmarshall them.

Parameters
val MutableList<T>?: The list of objects to be written. This value may be null.

writeTypedObject

Added in API level 23
fun <T : Parcelable!> writeTypedObject(
    val: T?,
    parcelableFlags: Int
): Unit

Flatten the Parcelable object into the parcel.

Parameters
val T?: The Parcelable object to be written. This value may be null.
parcelableFlags Int: Contextual flags as per Parcelable#writeToParcel(Parcel, int).

See Also

writeTypedSparseArray

Added in API level 29
fun <T : Parcelable!> writeTypedSparseArray(
    val: SparseArray<T>?,
    parcelableFlags: Int
): Unit

Flatten a SparseArray containing a particular object type into the parcel at the current dataPosition() and growing dataCapacity() if needed. The type of the objects in the array must be one that implements Parcelable. Unlike the generic writeSparseArray(android.util.SparseArray) method, however, only the raw data of the objects is written and not their type, so you must use the corresponding createTypedSparseArray(android.os.Parcelable.Creator).

Parameters
val SparseArray<T>?: The list of objects to be written. This value may be null.
parcelableFlags Int: The parcelable flags to use.

writeValue

Added in API level 1
fun writeValue(v: Any?): Unit

Flatten a generic object in to a parcel. The given Object value may currently be one of the following types:

  • null
  • String
  • Byte
  • Short
  • Integer
  • Long
  • Float
  • Double
  • Boolean
  • String[]
  • boolean[]
  • byte[]
  • int[]
  • long[]
  • Object[] (supporting objects of the same type defined here).
  • Bundle
  • Map (as supported by writeMap).
  • Any object that implements the Parcelable protocol.
  • Parcelable[]
  • CharSequence (as supported by TextUtils#writeToParcel).
  • List (as supported by writeList).
  • SparseArray (as supported by writeSparseArray(android.util.SparseArray)).
  • IBinder
  • Any object that implements Serializable (but see writeSerializable for caveats). Note that all of the previous types have relatively efficient implementations for writing to a Parcel; having to rely on the generic serialization approach is much less efficient and should be avoided whenever possible.

Parcelable objects are written with Parcelable#writeToParcel using contextual flags of 0. When serializing objects containing ParcelFileDescriptors, this may result in file descriptor leaks when they are returned from Binder calls (where Parcelable#PARCELABLE_WRITE_RETURN_VALUE should be used).

Parameters
v Any?: This value may be null.

Protected methods

finalize

Added in API level 1
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method

Properties

STRING_CREATOR

Added in API level 1
static val STRING_CREATOR: Parcelable.Creator<String!>!