android 对象序列化
来源:互联网 发布:scratch趣味编程实例 编辑:程序博客网 时间:2024/05/30 04:29
android 中自定义的对象序列化的问题有两个选择一个是Parcelable,另外一个是Serializable。
一 序列化原因:
1.永久性保存对象,保存对象的字节序列到本地文件中;
2.通过序列化对象在网络中传递对象;
3.通过序列化在进程间传递对象。
二 至于选取哪种可参考下面的原则:
1.在使用内存的时候,Parcelable 类比Serializable性能高,所以推荐使用Parcelable类。
2.Serializable在序列化的时候会产生大量的临时变量,从而引起频繁的GC。
3.Parcelable不能使用在要将数据存储在磁盘上的情况,因为Parcelable不能很好的保证数据的持续性在外界有变化的情况下。尽管Serializable效率低点, 也不提倡用,但在这种情况下,还是建议你用Serializable 。
实现:
1 Serializable 的实现,只需要继承 implements Serializable 即可。这只是给对象打了一个标记,系统会自动将其序列化。
2 Parcelabel 的实现,需要在类中添加一个静态成员变量 CREATOR,这个变量需要继承 Parcelable.Creator 接口。
public class MyParcelable implements Parcelable { private int mData; public int describeContents() { return 0; } public void writeToParcel(Parcel out, int flags) { out.writeInt(mData); } public static final Parcelable.Creator<MyParcelable> CREATOR = new Parcelable.Creator<MyParcelable>() { public MyParcelable createFromParcel(Parcel in) { return new MyParcelable(in); } public MyParcelable[] newArray(int size) { return new MyParcelable[size]; } }; private MyParcelable(Parcel in) { mData = in.readInt(); } }
0 0
- android对象序列化
- android 对象序列化
- android 对象序列化
- Android 对象序列化
- Android对象序列化
- android对象序列化
- Android对象序列化
- Android对象序列化
- Android对象序列化
- Android对象序列化
- Android bitmap对象序列化
- Android Serializalbe对象序列化
- android 序列化对象 Parcelable
- Android对象序列化实现
- Android—对象序列化
- Android 对象序列化 Parcelable
- 读书笔记-Android对象序列化
- Android 中的对象序列化
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
- SyntaxError: missing ; before statement,SCRIPT1004: 缺少 ';'
- 文件读写操作-Java
- K--近邻算法解析
- linux下安装oracle,本地PL/SQL连接Linux下的oracle导入表并新建用户和密码
- android 对象序列化
- advanced backend configuration(后端服务器高级配置)
- c++基础--隐式类类型转换
- [C++]IDictionary的用法
- xml-5处理
- PAT (Advanced Level) Practis 1039 Course List for Student (25)
- iOS之对象归档
- java 遍历Map的四种方法
- 《Visual c++从初学到精通》读书笔记(1)