Class Parcel
- java.lang.Object
-
- android.os.Parcel
-
public final class Parcel extends Object
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 generalParcelableinterface), and references to liveIBinderobjects 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
ParcelableAPI 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(byte),readByte(),writeDouble(double),readDouble(),writeFloat(float),readFloat(),writeInt(int),readInt(),writeLong(long),readLong(),writeString(java.lang.String),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:
-
writeBooleanArray(boolean[]),readBooleanArray(boolean[]),createBooleanArray() -
writeByteArray(byte[]),writeByteArray(byte[], int, int),readByteArray(byte[]),createByteArray() -
writeCharArray(char[]),readCharArray(char[]),createCharArray() -
writeDoubleArray(double[]),readDoubleArray(double[]),createDoubleArray() -
writeFloatArray(float[]),readFloatArray(float[]),createFloatArray() -
writeIntArray(int[]),readIntArray(int[]),createIntArray() -
writeLongArray(long[]),readLongArray(long[]),createLongArray() -
writeStringArray(String[]),readStringArray(String[]),createStringArray(). -
writeSparseBooleanArray(SparseBooleanArray),readSparseBooleanArray().
Parcelables
The
Parcelableprotocol provides an extremely efficient (but low-level) protocol for objects to write and read themselves from Parcels. You can use the direct methodswriteParcelable(Parcelable, int)andreadParcelable(ClassLoader)orwriteParcelableArray(T[], int)andreadParcelableArray(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(T, int),writeTypedArray(T[], int),writeTypedList(java.util.List<T>),readTypedObject(android.os.Parcelable.Creator<T>),createTypedArray(android.os.Parcelable.Creator<T>)andcreateTypedArrayList(android.os.Parcelable.Creator<T>). 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 appropriateParcelable.Creatorinstead to properly construct the new object and read its data. (To more efficient write and read a single Parceable object that is not null, you can directly callParcelable.writeToParcelandParcelable.Creator.createFromParcelyourself.)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 arewriteBundle(Bundle),readBundle(), andreadBundle(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.
Binderobjects are a core facility of Android's general cross-process communication system. TheIBinderinterface 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 arewriteStrongBinder(IBinder),writeStrongInterface(IInterface),readStrongBinder(),#writeBinderArray(IBinder[]),#readBinderArray(IBinder[]),#createBinderArray(),#writeBinderList(List),#readBinderList(List),#createBinderArrayList().FileDescriptor objects, representing raw Linux file descriptor identifiers, can be written and
ParcelFileDescriptorobjects 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 arewriteFileDescriptor(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(Object)andreadValue(ClassLoader)methods which define the types of objects allowed. The container methods arewriteArray(Object[]),readArray(ClassLoader),writeList(List),readList(List, ClassLoader),readArrayList(ClassLoader),writeMap(Map),readMap(Map, ClassLoader),writeSparseArray(SparseArray),readSparseArray(ClassLoader). -
-
-
Field Summary
Fields Modifier and Type Field Description static Parcelable.Creator<String>STRING_CREATOR
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidappendFrom(Parcel parcel, int offset, int length)boolean[]createBooleanArray()byte[]createByteArray()Read and return a byte[] object from the parcel.char[]createCharArray()double[]createDoubleArray()float[]createFloatArray()int[]createIntArray()long[]createLongArray()FileDescriptor[]createRawFileDescriptorArray()Read and return a new array of FileDescriptors from the parcel.String[]createStringArray()ArrayList<String>createStringArrayList()Read and return a new ArrayList containing String objects from the parcel that was written withwriteStringList(java.util.List<java.lang.String>)at the current dataPosition().<T> T[]createTypedArray(Parcelable.Creator<T> c)Read into the given List items IBinder objects that were written with#writeBinderListat the current dataPosition().<T> ArrayList<T>createTypedArrayList(Parcelable.Creator<T> c)Read and return a new ArrayList containing a particular object type from the parcel that was written withwriteTypedList(java.util.List<T>)at the current dataPosition().intdataAvail()Returns the amount of data remaining to be read from the parcel.intdataCapacity()Returns the total amount of space in the parcel.intdataPosition()Returns the current position in the parcel data.intdataSize()Returns the total amount of data contained in the parcel.protected voidfinalize()Invoked when the garbage collector has detected that this instance is no longer reachable.longgetBlobAshmemSize()static longgetGlobalAllocSize()byte[]marshall()Returns the raw bytes of the parcel.static Parcelobtain()Retrieve a new Parcel object from the pool.protected static Parcelobtain(int obj)protected static Parcelobtain(long obj)booleanpushAllowFds(boolean allowFds)Object[]readArray(ClassLoader loader)Read and return a new Object array from the parcel at the current dataPosition().ArrayListreadArrayList(ClassLoader loader)Read and return a CharSequence[] object from the parcel.voidreadArrayMap(ArrayMap outVal, ClassLoader loader)byte[]readBlob()Read a blob of data from the parcel and return it as a byte array.voidreadBooleanArray(boolean[] val)BundlereadBundle()Read and return a new Bundle object from the parcel at the current dataPosition().BundlereadBundle(ClassLoader loader)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.bytereadByte()Read a byte value from the parcel at the current dataPosition().voidreadByteArray(byte[] val)Read a byte[] object from the parcel and copy it into the given byte array.voidreadCharArray(char[] val)<T extends Parcelable>
TreadCreator(Parcelable.Creator<?> creator, ClassLoader loader)doublereadDouble()Read a double precision floating point value from the parcel at the current dataPosition().voidreadDoubleArray(double[] val)voidreadException()Special function for reading an exception result from the header of a parcel, to be used after receiving the result of a transaction.voidreadException(int code, String msg)Throw an exception with the given message.intreadExceptionCode()Parses the header of a Binder call's response Parcel and returns the exception code.ParcelFileDescriptorreadFileDescriptor()Read a FileDescriptor from the parcel at the current dataPosition().floatreadFloat()Read a floating point value from the parcel at the current dataPosition().voidreadFloatArray(float[] val)HashMapreadHashMap(ClassLoader loader)Please usereadBundle(ClassLoader)instead (whose data must have been written withwriteBundle(android.os.Bundle).intreadInt()Read an integer value from the parcel at the current dataPosition().voidreadIntArray(int[] val)voidreadList(List outVal, ClassLoader loader)Read into an existing List object from the parcel at the current dataPosition(), using the given class loader to load any enclosed Parcelables.longreadLong()Read a long integer value from the parcel at the current dataPosition().voidreadLongArray(long[] val)voidreadMap(Map outVal, ClassLoader loader)Please usereadBundle(ClassLoader)instead (whose data must have been written withwriteBundle(android.os.Bundle).<T extends Parcelable>
TreadParcelable(ClassLoader loader)Read and return a new Parcelable from the parcel.Parcelable[]readParcelableArray(ClassLoader loader)Read and return a new Parcelable array from the parcel.Parcelable.Creator<?>readParcelableCreator(ClassLoader loader)PersistableBundlereadPersistableBundle()Read and return a new Bundle object from the parcel at the current dataPosition().PersistableBundlereadPersistableBundle(ClassLoader loader)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.FileDescriptorreadRawFileDescriptor()voidreadRawFileDescriptorArray(FileDescriptor[] val)Read an array of FileDescriptors from a parcel.SerializablereadSerializable()Read and return a new Serializable object from the parcel.SizereadSize()Read a Size from the parcel at the current dataPosition().SizeFreadSizeF()Read a SizeF from the parcel at the current dataPosition().SparseArrayreadSparseArray(ClassLoader loader)Read and return a new SparseArray object from the parcel at the current dataPosition().SparseBooleanArrayreadSparseBooleanArray()Read and return a new SparseBooleanArray object from the parcel at the current dataPosition().StringreadString()Read a string value from the parcel at the current dataPosition().String[]readStringArray()Read and return a String[] object from the parcel.voidreadStringArray(String[] val)voidreadStringList(List<String> list)Read and return a new ArrayList containing IBinder objects from the parcel that was written with#writeBinderListat the current dataPosition().IBinderreadStrongBinder()Read an object from the parcel at the current dataPosition().<T> T[]readTypedArray(Parcelable.Creator<T> c)Deprecated.<T> voidreadTypedArray(T[] val, Parcelable.Creator<T> c)<T> voidreadTypedList(List<T> list, Parcelable.Creator<T> c)Read into the given List items containing a particular object type that were written withwriteTypedList(java.util.List<T>)at the current dataPosition().<T> TreadTypedObject(Parcelable.Creator<T> c)Read and return a typed Parcelable object from a parcel.ObjectreadValue(ClassLoader loader)Read a typed object from a parcel.voidrecycle()Put a Parcel object back into the pool.voidrestoreAllowFds(boolean lastValue)voidsetDataCapacity(int size)Change the capacity (current available space) of the parcel.voidsetDataPosition(int pos)Move the current read/write position in the parcel.voidsetDataSize(int size)Change the amount of data in the parcel.voidunmarshall(byte[] data, int offset, int length)Set the bytes in data to be the raw bytes of this Parcel.voidwriteArray(Object[] val)Flatten an Object array into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteArrayMap(ArrayMap<String,Object> val)voidwriteBlob(byte[] b)Write a blob of data into the parcel at the currentdataPosition(), growingdataCapacity()if needed.voidwriteBlob(byte[] b, int offset, int len)Write a blob of data into the parcel at the currentdataPosition(), growingdataCapacity()if needed.voidwriteBooleanArray(boolean[] val)voidwriteBundle(Bundle val)Flatten a Bundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteByte(byte val)Write a byte value into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteByteArray(byte[] b)Write a byte array into the parcel at the currentdataPosition(), growingdataCapacity()if needed.voidwriteByteArray(byte[] b, int offset, int len)Write a byte array into the parcel at the currentdataPosition(), growingdataCapacity()if needed.voidwriteCharArray(char[] val)voidwriteDouble(double val)Write a double precision floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteDoubleArray(double[] val)voidwriteException(Exception e)Special function for writing an exception result at the header of a parcel, to be used when returning an exception from a transaction.voidwriteFileDescriptor(FileDescriptor val)Write a FileDescriptor into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteFloat(float val)Write a floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteFloatArray(float[] val)voidwriteInt(int val)Write an integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteIntArray(int[] val)voidwriteInterfaceToken(String interfaceName)Report whether the parcel contains any marshalled file descriptors.voidwriteList(List val)Flatten a List into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteLong(long val)Write a long integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteLongArray(long[] val)voidwriteMap(Map val)Please usewriteBundle(android.os.Bundle)instead.voidwriteNoException()Special function for writing information at the front of the Parcel indicating that no exception occurred.voidwriteParcelable(Parcelable p, int parcelableFlags)Flatten the name of the class of the Parcelable and its contents into the parcel.<T extends Parcelable>
voidwriteParcelableArray(T[] value, int parcelableFlags)Write a heterogeneous array of Parcelable objects into the Parcel.voidwriteParcelableCreator(Parcelable p)voidwritePersistableBundle(PersistableBundle val)Flatten a PersistableBundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteRawFileDescriptor(FileDescriptor val)This will be the new name for writeFileDescriptor, for consistency.voidwriteRawFileDescriptorArray(FileDescriptor[] value)Write an array of FileDescriptor objects into the Parcel.voidwriteSerializable(Serializable s)Write a generic serializable object in to a Parcel.voidwriteSize(Size val)Flatten a Size into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteSizeF(SizeF val)Flatten a SizeF into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteSparseArray(SparseArray<Object> val)Flatten a generic SparseArray into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteSparseBooleanArray(SparseBooleanArray val)voidwriteString(String val)Write a string value into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteStringArray(String[] val)voidwriteStringList(List<String> val)Flatten a List containing String objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed.voidwriteStrongBinder(IBinder val)Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.voidwriteStrongInterface(IInterface val)Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.<T extends Parcelable>
voidwriteTypedArray(T[] val, int parcelableFlags)Flatten a List containing IBinder objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed.<T extends Parcelable>
voidwriteTypedList(List<T> val)Flatten a List containing a particular object type into the parcel, at the current dataPosition() and growing dataCapacity() if needed.<T extends Parcelable>
voidwriteTypedObject(T val, int parcelableFlags)Flatten the Parcelable object into the parcel.voidwriteValue(Object v)Flatten a generic object in to a parcel.
-
-
-
Field Detail
-
STRING_CREATOR
public static final Parcelable.Creator<String> STRING_CREATOR
-
-
Method Detail
-
obtain
public static Parcel obtain()
Retrieve a new Parcel object from the pool.
-
recycle
public final void recycle()
Put a Parcel object back into the pool. You must not touch the object after this call.
-
getGlobalAllocSize
public static long getGlobalAllocSize()
-
dataSize
public final int dataSize()
Returns the total amount of data contained in the parcel.
-
dataAvail
public final int dataAvail()
Returns the amount of data remaining to be read from the parcel. That is,dataSize()-dataPosition().
-
dataPosition
public final int dataPosition()
Returns the current position in the parcel data. Never more thandataSize().
-
dataCapacity
public final int dataCapacity()
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.
-
setDataSize
public final void setDataSize(int size)
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- The new number of bytes in the Parcel.
-
setDataPosition
public final void setDataPosition(int pos)
Move the current read/write position in the parcel.- Parameters:
pos- New offset in the parcel; must be between 0 anddataSize().
-
setDataCapacity
public final void setDataCapacity(int size)
Change the capacity (current available space) of the parcel.- Parameters:
size- The new capacity of the parcel, in bytes. Can not be less thandataSize()-- that is, you can not drop existing data with this method.
-
pushAllowFds
public final boolean pushAllowFds(boolean allowFds)
-
restoreAllowFds
public final void restoreAllowFds(boolean lastValue)
-
marshall
public final byte[] marshall()
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.
-
unmarshall
public final void unmarshall(byte[] data, int offset, int length)Set the bytes in data to be the raw bytes of this Parcel.
-
appendFrom
public final void appendFrom(Parcel parcel, int offset, int length)
-
writeInterfaceToken
public final void writeInterfaceToken(String interfaceName)
Report whether the parcel contains any marshalled file descriptors.
-
writeByteArray
public final void writeByteArray(byte[] b)
Write a byte array into the parcel at the currentdataPosition(), growingdataCapacity()if needed.- Parameters:
b- Bytes to place into the parcel.
-
writeByteArray
public final void writeByteArray(byte[] b, int offset, int len)Write a byte array into the parcel at the currentdataPosition(), growingdataCapacity()if needed.- Parameters:
b- Bytes to place into the parcel.offset- Index of first byte to be written.len- Number of bytes to write.
-
writeBlob
public final void writeBlob(byte[] b)
Write a blob of data into the parcel at the currentdataPosition(), growingdataCapacity()if needed.- Parameters:
b- Bytes to place into the parcel.
-
writeBlob
public final void writeBlob(byte[] b, int offset, int len)Write a blob of data into the parcel at the currentdataPosition(), growingdataCapacity()if needed.- Parameters:
b- Bytes to place into the parcel.offset- Index of first byte to be written.len- Number of bytes to write.
-
writeInt
public final void writeInt(int val)
Write an integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeLong
public final void writeLong(long val)
Write a long integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeFloat
public final void writeFloat(float val)
Write a floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeDouble
public final void writeDouble(double val)
Write a double precision floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeString
public final void writeString(String val)
Write a string value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeStrongBinder
public final void writeStrongBinder(IBinder val)
Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeStrongInterface
public final void writeStrongInterface(IInterface val)
Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeFileDescriptor
public final void writeFileDescriptor(FileDescriptor val)
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(android.os.Parcel, int)instead, which accepts contextual flags and will close the original file descriptor ifParcelable.PARCELABLE_WRITE_RETURN_VALUEis set.
-
writeRawFileDescriptor
public final void writeRawFileDescriptor(FileDescriptor val)
This will be the new name for writeFileDescriptor, for consistency.
-
writeRawFileDescriptorArray
public final void writeRawFileDescriptorArray(FileDescriptor[] value)
Write an array of FileDescriptor objects into the Parcel.- Parameters:
value- The array of objects to be written.
-
writeByte
public final void writeByte(byte val)
Write a byte value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeMap
public final void writeMap(Map val)
Please usewriteBundle(android.os.Bundle)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 usingwriteValue(java.lang.Object)and must follow the specification there.It is strongly recommended to use
writeBundle(android.os.Bundle)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.
-
writeBundle
public final void writeBundle(Bundle val)
Flatten a Bundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writePersistableBundle
public final void writePersistableBundle(PersistableBundle val)
Flatten a PersistableBundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeSize
public final void writeSize(Size val)
Flatten a Size into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeSizeF
public final void writeSizeF(SizeF val)
Flatten a SizeF into the parcel at the current dataPosition(), growing dataCapacity() if needed.
-
writeList
public final void writeList(List val)
Flatten a List into the parcel at the current dataPosition(), growing dataCapacity() if needed. The List values are written usingwriteValue(java.lang.Object)and must follow the specification there.
-
writeArray
public final void writeArray(Object[] val)
Flatten an Object array into the parcel at the current dataPosition(), growing dataCapacity() if needed. The array values are written usingwriteValue(java.lang.Object)and must follow the specification there.
-
writeSparseArray
public final void writeSparseArray(SparseArray<Object> val)
Flatten a generic SparseArray into the parcel at the current dataPosition(), growing dataCapacity() if needed. The SparseArray values are written usingwriteValue(java.lang.Object)and must follow the specification there.
-
writeSparseBooleanArray
public final void writeSparseBooleanArray(SparseBooleanArray val)
-
writeBooleanArray
public final void writeBooleanArray(boolean[] val)
-
createBooleanArray
public final boolean[] createBooleanArray()
-
readBooleanArray
public final void readBooleanArray(boolean[] val)
-
writeCharArray
public final void writeCharArray(char[] val)
-
createCharArray
public final char[] createCharArray()
-
readCharArray
public final void readCharArray(char[] val)
-
writeIntArray
public final void writeIntArray(int[] val)
-
createIntArray
public final int[] createIntArray()
-
readIntArray
public final void readIntArray(int[] val)
-
writeLongArray
public final void writeLongArray(long[] val)
-
createLongArray
public final long[] createLongArray()
-
readLongArray
public final void readLongArray(long[] val)
-
writeFloatArray
public final void writeFloatArray(float[] val)
-
createFloatArray
public final float[] createFloatArray()
-
readFloatArray
public final void readFloatArray(float[] val)
-
writeDoubleArray
public final void writeDoubleArray(double[] val)
-
createDoubleArray
public final double[] createDoubleArray()
-
readDoubleArray
public final void readDoubleArray(double[] val)
-
writeStringArray
public final void writeStringArray(String[] val)
-
createStringArray
public final String[] createStringArray()
-
readStringArray
public final void readStringArray(String[] val)
-
writeTypedList
public final <T extends Parcelable> void writeTypedList(List<T> val)
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- The list of objects to be written.- See Also:
createTypedArrayList(android.os.Parcelable.Creator<T>),readTypedList(java.util.List<T>, android.os.Parcelable.Creator<T>),Parcelable
-
writeStringList
public final void writeStringList(List<String> val)
Flatten a List containing String objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed. They can later be retrieved withcreateStringArrayList()orreadStringList(java.util.List<java.lang.String>).- Parameters:
val- The list of strings to be written.- See Also:
createStringArrayList(),readStringList(java.util.List<java.lang.String>)
-
writeTypedArray
public final <T extends Parcelable> void writeTypedArray(T[] val, int parcelableFlags)
Flatten a List containing IBinder objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed. They can later be retrieved with#createBinderArrayListor#readBinderList.- Parameters:
val- The list of strings to be written.- See Also:
#createBinderArrayList,#readBinderList
-
writeTypedObject
public final <T extends Parcelable> void writeTypedObject(T val, int parcelableFlags)
Flatten the Parcelable object into the parcel.- Parameters:
val- The Parcelable object to be written.parcelableFlags- Contextual flags as perParcelable.writeToParcel().- See Also:
readTypedObject(android.os.Parcelable.Creator<T>)
-
writeValue
public final void writeValue(Object v)
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(java.util.Map)). - Any object that implements the
Parcelableprotocol. - Parcelable[]
- CharSequence (as supported by
TextUtils#writeToParcel). - List (as supported by
writeList(java.util.List)). -
SparseArray(as supported bywriteSparseArray(SparseArray)). -
IBinder - Any object that implements Serializable (but see
writeSerializable(java.io.Serializable)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.
Parcelableobjects are written withParcelable.writeToParcel(android.os.Parcel, int)using contextual flags of 0. When serializing objects containingParcelFileDescriptors, this may result in file descriptor leaks when they are returned from Binder calls (whereParcelable.PARCELABLE_WRITE_RETURN_VALUEshould be used).
-
writeParcelable
public final void writeParcelable(Parcelable p, int parcelableFlags)
Flatten the name of the class of the Parcelable and its contents into the parcel.- Parameters:
p- The Parcelable object to be written.parcelableFlags- Contextual flags as perParcelable.writeToParcel().
-
writeParcelableCreator
public final void writeParcelableCreator(Parcelable p)
-
writeSerializable
public final void writeSerializable(Serializable s)
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.
-
writeException
public final void writeException(Exception e)
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- The Exception to be written.- See Also:
writeNoException(),readException()
-
writeNoException
public final void writeNoException()
Special function for writing information at the front of the Parcel indicating that no exception occurred.
-
readException
public final void readException()
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.
-
readExceptionCode
public final int readExceptionCode()
Parses the header of a Binder call's response Parcel and returns the exception code. Deals with lite or fat headers. In the common successful case, this header is generally zero. In less common cases, it's a small negative number and will be followed by an error string. This exists purely for android.database.DatabaseUtils and insulating it from having to handle fat headers as returned by e.g. StrictMode-induced RPC responses.
-
readException
public final void readException(int code, String msg)Throw an exception with the given message. Not intended for use outside the Parcel class.- Parameters:
code- Used to determine which exception class to throw.msg- The exception message.
-
readInt
public final int readInt()
Read an integer value from the parcel at the current dataPosition().
-
readLong
public final long readLong()
Read a long integer value from the parcel at the current dataPosition().
-
readFloat
public final float readFloat()
Read a floating point value from the parcel at the current dataPosition().
-
readDouble
public final double readDouble()
Read a double precision floating point value from the parcel at the current dataPosition().
-
readString
public final String readString()
Read a string value from the parcel at the current dataPosition().
-
readStrongBinder
public final IBinder readStrongBinder()
Read an object from the parcel at the current dataPosition().
-
readFileDescriptor
public final ParcelFileDescriptor readFileDescriptor()
Read a FileDescriptor from the parcel at the current dataPosition().
-
readRawFileDescriptor
public final FileDescriptor readRawFileDescriptor()
-
createRawFileDescriptorArray
public final FileDescriptor[] createRawFileDescriptorArray()
Read and return a new array of FileDescriptors from the parcel.- Returns:
- the FileDescriptor array, or null if the array is null.
-
readRawFileDescriptorArray
public final void readRawFileDescriptorArray(FileDescriptor[] val)
Read an array of FileDescriptors from a parcel. The passed array must be exactly the length of the array in the parcel.
-
readByte
public final byte readByte()
Read a byte value from the parcel at the current dataPosition().
-
readMap
public final void readMap(Map outVal, ClassLoader loader)
Please usereadBundle(ClassLoader)instead (whose data must have been written withwriteBundle(android.os.Bundle). Read into an existing Map object from the parcel at the current dataPosition().
-
readList
public final void readList(List outVal, ClassLoader loader)
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.
-
readHashMap
public final HashMap readHashMap(ClassLoader loader)
Please usereadBundle(ClassLoader)instead (whose data must have been written withwriteBundle(android.os.Bundle). 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.
-
readBundle
public final Bundle readBundle()
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
public final Bundle readBundle(ClassLoader loader)
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.
-
readPersistableBundle
public final PersistableBundle readPersistableBundle()
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
public final PersistableBundle readPersistableBundle(ClassLoader loader)
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.
-
readSize
public final Size readSize()
Read a Size from the parcel at the current dataPosition().
-
readSizeF
public final SizeF readSizeF()
Read a SizeF from the parcel at the current dataPosition().
-
createByteArray
public final byte[] createByteArray()
Read and return a byte[] object from the parcel.
-
readByteArray
public final void readByteArray(byte[] val)
Read a byte[] object from the parcel and copy it into the given byte array.
-
readBlob
public final byte[] readBlob()
Read a blob of data from the parcel and return it as a byte array.
-
readStringArray
public final String[] readStringArray()
Read and return a String[] object from the parcel.
-
readArrayList
public final ArrayList readArrayList(ClassLoader loader)
Read and return a CharSequence[] object from the parcel.
-
readArray
public final Object[] readArray(ClassLoader loader)
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.
-
readSparseArray
public final SparseArray readSparseArray(ClassLoader loader)
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.
-
readSparseBooleanArray
public final SparseBooleanArray readSparseBooleanArray()
Read and return a new SparseBooleanArray object from the parcel at the current dataPosition(). Returns null if the previously written list object was null.
-
createTypedArrayList
public final <T> ArrayList<T> createTypedArrayList(Parcelable.Creator<T> c)
Read and return a new ArrayList containing a particular object type from the parcel that was written withwriteTypedList(java.util.List<T>)at the current dataPosition(). Returns null if the previously written list object was null. The list must have previously been written viawriteTypedList(java.util.List<T>)with the same object type.- Returns:
- A newly created ArrayList containing objects with the same data as those that were previously written.
- See Also:
writeTypedList(java.util.List<T>)
-
readTypedList
public final <T> void readTypedList(List<T> list, Parcelable.Creator<T> c)
Read into the given List items containing a particular object type that were written withwriteTypedList(java.util.List<T>)at the current dataPosition(). The list must have previously been written viawriteTypedList(java.util.List<T>)with the same object type.- See Also:
writeTypedList(java.util.List<T>)
-
createStringArrayList
public final ArrayList<String> createStringArrayList()
Read and return a new ArrayList containing String objects from the parcel that was written withwriteStringList(java.util.List<java.lang.String>)at the current dataPosition(). Returns null if the previously written list object was null.- Returns:
- A newly created ArrayList containing strings with the same data as those that were previously written.
- See Also:
writeStringList(java.util.List<java.lang.String>)
-
readStringList
public final void readStringList(List<String> list)
Read and return a new ArrayList containing IBinder objects from the parcel that was written with#writeBinderListat the current dataPosition(). Returns null if the previously written list object was null.- See Also:
#writeBinderList
-
createTypedArray
public final <T> T[] createTypedArray(Parcelable.Creator<T> c)
Read into the given List items IBinder objects that were written with#writeBinderListat the current dataPosition().- Returns:
- A newly created ArrayList containing strings with the same data as those that were previously written.
- See Also:
#writeBinderList
-
readTypedArray
public final <T> void readTypedArray(T[] val, Parcelable.Creator<T> c)
-
readTypedArray
@Deprecated public final <T> T[] readTypedArray(Parcelable.Creator<T> c)
Deprecated.
-
readTypedObject
public final <T> T readTypedObject(Parcelable.Creator<T> c)
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 viawriteTypedObject(T, int)with the same object type.- Returns:
- A newly created object of the type that was previously written.
- See Also:
writeTypedObject(T, int)
-
writeParcelableArray
public final <T extends Parcelable> void writeParcelableArray(T[] value, int parcelableFlags)
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 thanwriteTypedArray(T[], int), but will correctly handle an array containing more than one type of object.- Parameters:
value- The array of objects to be written.parcelableFlags- Contextual flags as perParcelable.writeToParcel().- See Also:
writeTypedArray(T[], int)
-
readValue
public final Object readValue(ClassLoader loader)
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.
-
readParcelable
public final <T extends Parcelable> T readParcelable(ClassLoader loader)
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- A ClassLoader from which to instantiate the Parcelable object, or null for the default class loader.- Returns:
- Returns the newly created Parcelable, or null if a null object has been written.
- Throws:
BadParcelableException- Throws BadParcelableException if there was an error trying to instantiate the Parcelable.
-
readCreator
public final <T extends Parcelable> T readCreator(Parcelable.Creator<?> creator, ClassLoader loader)
-
readParcelableCreator
public final Parcelable.Creator<?> readParcelableCreator(ClassLoader loader)
-
readParcelableArray
public final Parcelable[] readParcelableArray(ClassLoader loader)
Read and return a new Parcelable array from the parcel. The given class loader will be used to load any enclosed Parcelables.- Returns:
- the Parcelable array, or null if the array is null
-
readSerializable
public final Serializable readSerializable()
Read and return a new Serializable object from the parcel.- Returns:
- the Serializable object, or null if the Serializable name wasn't found in the parcel.
-
obtain
protected static final Parcel obtain(int obj)
-
obtain
protected static final Parcel obtain(long obj)
-
finalize
protected void finalize() throws ThrowableDescription copied from class:ObjectInvoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.Note that objects that override
finalizeare significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicitclosemethod (and implementCloseable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like aBigIntegerwhere typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.If you must use finalizers, consider at least providing your own
ReferenceQueueand having your own thread process that queue.Unlike constructors, finalizers are not automatically chained. You are responsible for calling
super.finalize()yourself.Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
-
readArrayMap
public void readArrayMap(ArrayMap outVal, ClassLoader loader)
-
getBlobAshmemSize
public long getBlobAshmemSize()
-
-