Android中Parcelable和Serializable的区别

来源:互联网 发布:反射 java 编辑:程序博客网 时间:2024/04/27 13:41

推荐阅读:http://www.developerphil.com/parcelable-vs-serializable/

android 中自定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable。

文中的结论直接拿来了:

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.

对比二者的优劣势

Parcelable

优势:高效

劣势:实现较麻烦;不能持久化;


Serializable

优势:实现简单;可以持久化;

劣势:低效

0 0
原创粉丝点击