为什么Android为序列化对象提供了两个接口?序列化对象与Android Binder和AIDL文件interopt ?


当前回答

打包比使用Binder序列化快得多,因为序列化使用反射并导致许多GC。Parcelable是为了优化传递对象而设计的。

这是参考链接。 http://www.developerphil.com/parcelable-vs-serializable/

其他回答

我将成为一个支持Serializable的人。由于这些设备比几年前好得多,速度上的差异已经不那么明显了,而且还有其他更微妙的差异。更多信息请参见我的博客文章。

如果你在android studio中使用paracelable插件,parcelable的实现可以更快。搜索Android Parcelable代码生成器

If you want to be a good citizen, take the extra time to implement Parcelable since it will perform 10 times faster and use less resources. However, in most cases, the slowness of Serializable won’t be noticeable. Feel free to use it but remember that serialization is an expensive operation so keep it to a minimum. If you are trying to pass a list with thousands of serialized objects, it is possible that the whole process will take more than a second. It can make transitions or rotation from portrait to lanscape feel very sluggish.

来源:http://www.developerphil.com/parcelable-vs-serializable/

Parcelable将对象转换为字节流,以便在Android的进程之间传递对象。

序列化将POJO转换为字符串(JSON字符串),并用于跨平台传输对象信息。

打包比使用Binder序列化快得多,因为序列化使用反射并导致许多GC。Parcelable是为了优化传递对象而设计的。

这是参考链接。 http://www.developerphil.com/parcelable-vs-serializable/