打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
2. Parcel
可以通过IBinder传递的信息的容器(包括数据和对象引用)。一个Parcel对象可以在一个线程中打包对象,在另一个线程中解开并获取到这些数据。也可以是一个IBinder对象的引用。

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不是出于一般目的的序列化机制。这个类是为了提高线程间通信效率而设计的。所以,将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.
Public Methods
final void appendFrom(Parcel parcel, int offset, int length)
final IBinder[] createBinderArray()
final ArrayList<IBinder> createBinderArrayList()
Read and return a new ArrayList containing IBinder objects from the parcel that was written with writeBinderList(List) at the current dataPosition().
final boolean[] createBooleanArray()
final byte[] createByteArray()
Read and return a byte[] object from the parcel.
final char[] createCharArray()
final double[] createDoubleArray()
final float[] createFloatArray()
final int[] createIntArray()
final long[] createLongArray()
final String[] createStringArray()
final ArrayList<String> createStringArrayList()
Read and return a new ArrayList containing String objects from the parcel that was written with writeStringList(List) at the current dataPosition().
final <T> T[] createTypedArray(Creator<T> c)
Read and return a new array containing a particular object type from the parcel at the current dataPosition().
final <T> ArrayList<T> createTypedArrayList(Creator<T> c)
Read and return a new ArrayList containing a particular object type from the parcel that was written with writeTypedList(List) at the current dataPosition().
final int dataAvail()
Returns the amount of data remaining to be read from the parcel.
final int dataCapacity()
Returns the total amount of space in the parcel.
final int dataPosition()
Returns the current position in the parcel data.
final int dataSize()
Returns the total amount of data contained in the parcel.
final void enforceInterface(String interfaceName)
final boolean hasFileDescriptors()
Report whether the parcel contains any marshalled file descriptors.
final byte[] marshall()
Returns the raw bytes of the parcel.
static Parcel obtain()
Retrieve a new Parcel object from the pool.
final Object[] readArray(ClassLoader loader)
Read and return a new Object array from the parcel at the current dataPosition().
final ArrayList readArrayList(ClassLoader loader)
Read and return a new ArrayList object from the parcel at the current dataPosition().
final void readBinderArray(IBinder[] val)
final void readBinderList(List<IBinder> list)
Read into the given List items IBinder objects that were written with writeBinderList(List) at the current dataPosition().
final void readBooleanArray(boolean[] val)
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.
final Bundle readBundle()
Read and return a new Bundle object from the parcel at the current dataPosition().
final byte readByte()
Read a byte value from the parcel at the current dataPosition().
final void readByteArray(byte[] val)
Read a byte[] object from the parcel and copy it into the given byte array.
final void readCharArray(char[] val)
final double readDouble()
Read a double precision floating point value from the parcel at the current dataPosition().
final void readDoubleArray(double[] val)
final void readException(int code, String msg)
Throw an exception with the given message.
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.
final ParcelFileDescriptor readFileDescriptor()
Read a FileDescriptor from the parcel at the current dataPosition().
final float readFloat()
Read a floating point value from the parcel at the current dataPosition().
final void readFloatArray(float[] val)
final HashMap readHashMap(ClassLoader loader)
Please use readBundle(ClassLoader) instead (whose data must have been written with writeBundle(Bundle).
final int readInt()
Read an integer value from the parcel at the current dataPosition().
final void readIntArray(int[] val)
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.
final long readLong()
Read a long integer value from the parcel at the current dataPosition().
final void readLongArray(long[] val)
final void readMap(Map outVal, ClassLoader loader)
Please use readBundle(ClassLoader) instead (whose data must have been written with writeBundle(Bundle).
final <T extends Parcelable> T readParcelable(ClassLoader loader)
Read and return a new Parcelable from the parcel.
final Parcelable[] readParcelableArray(ClassLoader loader)
Read and return a new Parcelable array from the parcel.
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.
final PersistableBundle readPersistableBundle()
Read and return a new Bundle object from the parcel at the current dataPosition().
final Serializable readSerializable()
Read and return a new Serializable object from the parcel.
final Size readSize()
Read a Size from the parcel at the current dataPosition().
final SizeF readSizeF()
Read a SizeF from the parcel at the current dataPosition().
final SparseArray readSparseArray(ClassLoader loader)
Read and return a new SparseArray object from the parcel at the current dataPosition().
final SparseBooleanArray readSparseBooleanArray()
Read and return a new SparseBooleanArray object from the parcel at the current dataPosition().
final String readString()
Read a string value from the parcel at the current dataPosition().
final void readStringArray(String[] val)
final void readStringList(List<String> list)
Read into the given List items String objects that were written with writeStringList(List) at the current dataPosition().
final IBinder readStrongBinder()
Read an object from the parcel at the current dataPosition().
final <T> void readTypedArray(T[] val, Creator<T> c)
final <T> void readTypedList(List<T> list, Creator<T> c)
Read into the given List items containing a particular object type that were written with writeTypedList(List) at the current dataPosition().
final Object readValue(ClassLoader loader)
Read a typed object from a parcel.
final void recycle()
Put a Parcel object back into the pool.
final void setDataCapacity(int size)
Change the capacity (current available space) of the parcel.
final void setDataPosition(int pos)
Move the current read/write position in the parcel.
final void setDataSize(int size)
Change the amount of data in the parcel.
final void unmarshall(byte[] data, int offest, int length)
Set the bytes in data to be the raw bytes of this Parcel.
final void writeArray(Object[] val)
Flatten an Object array into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeBinderArray(IBinder[] val)
final void writeBinderList(List<IBinder> val)
Flatten a List containing IBinder objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed.
final void writeBooleanArray(boolean[] val)
final void writeBundle(Bundle val)
Flatten a Bundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeByte(byte val)
Write a byte value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeByteArray(byte[] b, int offset, int len)
Write a byte array into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeByteArray(byte[] b)
Write a byte array into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeCharArray(char[] val)
final void writeDouble(double val)
Write a double precision floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeDoubleArray(double[] val)
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.
final void writeFileDescriptor(FileDescriptor val)
Write a FileDescriptor into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeFloat(float val)
Write a floating point value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeFloatArray(float[] val)
final void writeInt(int val)
Write an integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeIntArray(int[] val)
final void writeInterfaceToken(String interfaceName)
Store or read an IBinder interface token in the parcel at the current dataPosition().
final void writeList(List val)
Flatten a List into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeLong(long val)
Write a long integer value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeLongArray(long[] val)
final void writeMap(Map val)
Please use writeBundle(Bundle) instead.
final void writeNoException()
Special function for writing information at the front of the Parcel indicating that no exception occurred.
final void writeParcelable(Parcelable p, int parcelableFlags)
Flatten the name of the class of the Parcelable and its contents into the parcel.
final <T extends Parcelable> void writeParcelableArray(T[] value, int parcelableFlags)
Write a heterogeneous array of Parcelable objects into the Parcel.
final void writePersistableBundle(PersistableBundle val)
Flatten a PersistableBundle into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeSerializable(Serializable s)
Write a generic serializable object in to a Parcel.
final void writeSize(Size val)
Flatten a Size into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeSizeF(SizeF val)
Flatten a SizeF into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeSparseArray(SparseArray<Object> val)
Flatten a generic SparseArray into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeSparseBooleanArray(SparseBooleanArray val)
final void writeString(String val)
Write a string value into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeStringArray(String[] val)
final void writeStringList(List<String> val)
Flatten a List containing String objects into the parcel, at the current dataPosition() and growing dataCapacity() if needed.
final void writeStrongBinder(IBinder val)
Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final void writeStrongInterface(IInterface val)
Write an object into the parcel at the current dataPosition(), growing dataCapacity() if needed.
final <T extends Parcelable> void writeTypedArray(T[] val, int parcelableFlags)
Flatten a heterogeneous array containing a particular object type into the parcel, at the current dataPosition() and growing dataCapacity() if needed.
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.
final void writeValue(Object v)
Flatten a generic object in to a parcel.
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android源码之Parcel
这是一段4位共阳极数码管”从0到9循环显示数字“的程序,不知道是什么意思望前辈们来看看~~
终于明白为什么要加 final 关键字了!
基于redis分布式缓存队列实现抢红包功能
数据结构之链表--单向循环链表
圆点博士——代码注释——初版——来自波波——accfilter.c
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服