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


当前回答

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/

其他回答

Serializable是一个标准的Java接口。您只需通过实现接口将类标记为Serializable, Java将在某些情况下自动序列化它。

Parcelable是一个Android特定的接口,你可以自己实现序列化。创建它的目的是要比Serializable高效得多,并解决默认Java序列化方案的一些问题。

我相信Binder和AIDL可以用于可打包对象。

但是,你可以在intent中使用Serializable对象。

1. 可序列化的

@see http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

什么接口?

是标准的Java接口吗

速度

比Parcelable慢

2. Parcelable

@see http://developer.android.com/reference/android/os/Parcelable.html

什么接口?

android。操作系统接口 这意味着谷歌开发的Parcelable在android上有更好的性能

速度

更快(因为它针对android开发进行了优化)

综上所述

要知道Serializable是一个标准的Java接口,Parcelable是Android开发的接口

你可以在intent中使用serializable对象,但是在使serialize成为Parcelable对象的时候,它会给出一个严重的异常,比如NotSerializableException。不建议使用serializable和Parcelable。所以最好是扩展Parcelable与你想要使用的对象捆绑和意图。由于这个Parcelable是android特定的,所以它没有任何副作用。 :)

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/

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