Android之Parcel

一、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是一个容器,可以包含数据或者对象引用,Parcel作为消息的容器通过Binder发送消息,消息包含数据和对象引用。Parcel支持序列化与IPC通信后另一侧进行反序列化。Parcel主要用来进程间IPC通信的。

  在Andorid中,使用Binder进行IPC通信,其数据载体就是Parcel,也就是说Binder IPC通信使用的数据结构是Parcel。另外还有应用的Surface传递给SurfaceFlinger服务,Surface继承自Parcelable。

二、原理

  Parcel是一套机制,可以将序列化后的数据写入到共享内存中,其它进程通过Parcel将数据读取,并反序列化成对象。

 

原文地址:https://www.cnblogs.com/naray/p/15365950.html