Android中Parcelable序列化总结
在使用Parcelable对android中数据的序列化操作还是比较有用的,有人做过通过对比Serializable和Parcelable在android中序列化操作对象的速度比对,大概Parcelable相比Serializable要快10倍左右、、、给一个连接可以瞅瞅他们序列化的区别http://greenrobot.me/devpost/android-parcelable-serializable/
下面来总结一下我们基本数据类型、对象、数组、list等做Parcelable的方法,主要是做个总结直接看下code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
package com.suning.mobile.paysdk.pay; import java.util.ArrayList; import android.os.Parcel; import android.os.Parcelable; import com.yaya.test.OrderInfoBean; /** * * 〈一句话功能简述〉<br> * 〈功能详细描述〉 数据类型序列化 */ public class ParcelableType implements Parcelable { /** int 类型 */ int age; /** String 类型 */ String name; /** boolean 注意该boolean的get和set方法 **/ boolean isGood; /** boolean 类型 **/ boolean complete; /** 数组 **/ private String[] ids; /** 对象 [内部已经序列化] **/ private OrderInfoBean bean; /** list **/ private ArrayList<orderinfobean> listBeans; /** * 默认构造方法 */ public ParcelableType() { // TODO Auto-generated constructor stub } public ParcelableType(Parcel in) { readFromParcel(in); } /*** * 默认实现 */ @Override public int describeContents() { // TODO Auto-generated method stub return 0 ; } @Override public void writeToParcel(Parcel dest, int flags) { /** int 写入 **/ dest.writeInt(age); /** string 写入 **/ dest.writeString(name); /** boolean 写入 **/ dest.writeInt(isGood ? 1 : 0 ); /** boolean 写入 **/ dest.writeInt(complete ? 1 : 0 ); /** 数组 写入 **/ if (ids != null ) { dest.writeInt(ids.length); } else { dest.writeInt( 0 ); } dest.writeStringArray(ids); /** 对象 写入 **/ dest.writeParcelable(bean, flags); /** list 写入 **/ dest.writeList(listBeans); } @SuppressWarnings ( "unchecked" ) private void readFromParcel(Parcel in) { /** int 读出 */ age = in.readInt(); /** stirng 读出 */ name = in.readString(); /** boolean 读出 */ isGood = (in.readInt() == 1 ) ? true : false ; /** boolean 读出 */ complete = (in.readInt() == 1 ) ? true : false ; /** 数组 读出 */ int length = in.readInt(); ids = new String[length]; in.readStringArray(ids); /** 对象 读出 */ bean = in.readParcelable(OrderInfoBean. class .getClassLoader()); /** list 读出 */ listBeans = in.readArrayList(OrderInfoBean. class .getClassLoader()); } public static final Parcelable.Creator<parcelabletype> CREATOR = new Parcelable.Creator<parcelabletype>() { public ParcelableType createFromParcel(Parcel in) { return new ParcelableType(in); } public ParcelableType[] newArray( int size) { return new ParcelableType[size]; } }; public int getAge() { return age; } public void setAge( int age) { this .age = age; } public String getName() { return name; } public void setName(String name) { this .name = name; } /** * * 功能描述: <br> * 〈功能详细描述〉 fastJson解析时需要格式 */ public boolean isIsGood() { return isGood; } public void setIsGood( boolean isGood) { this .isGood = isGood; } public boolean isComplete() { return complete; } public void setComplete( boolean complete) { this .complete = complete; } public String[] getIds() { return ids; } public void setIds(String[] ids) { this .ids = ids; } public OrderInfoBean getBean() { return bean; } public void setBean(OrderInfoBean bean) { this .bean = bean; } public ArrayList<orderinfobean> getListBeans() { return listBeans; } public void setListBeans(ArrayList<orderinfobean> listBeans) { this .listBeans = listBeans; } } |
Android中Parcelable序列化总结的更多相关文章
- Android中Parcelable接口
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- (转)Android中Parcelable接口用法
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- Android中Parcelable和Serializable接口用法
1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...
- Android中Parcelable与Serializable接口用法
转自: Android中Parcelable接口用法 1. Parcelable接口 Interface for classes whose instances can be written to a ...
- Android中Parcelable接口的使用
在做开发的过程中,序列化是非常常见的.比如要将对象保存本地磁盘或者在网络上传输等.实现序列化有两种方式,一种是实现Serializable接口,第二种是实现Parcelable. Serializab ...
- Android 使用Parcelable序列化对象
转:http://ipjmc.iteye.com/blog/1314145 Android序列化对象主要有两种方法,实现Serializable接口.或者实现Parcelable接口.实现 ...
- Android中Parcelable的使用
转载请标明出处 :https://www.cnblogs.com/tangZH/p/10998065.html Parcelable与Serializable Serializable是Java为我 ...
- Android中Parcelable的原理和使用方法
Parcelable的简单介绍 介绍Parcelable不得不先提一下Serializable接口,Serializable是Java为我们提供的一个标准化的序列化接口,那什么是序列化呢? 进行And ...
- Android中Parcelable接口用法
from: http://www.cnblogs.com/renqingping/archive/2012/10/25/Parcelable.html Interface for classes wh ...
随机推荐
- 转:C++:从子类访问父类的私有函数
众所周知,c和c++的数组都是不安全的,因为无论c还是c++都不提供数组边界检查功能,这使得数组溢出成为可能.从某个意义上说,c和c++是一种缺少监督的语言,然而这也正是其魅力所在.c++给予程序员更 ...
- cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(四)-马里奥平移
上一篇博文提到,程序如何获取键盘输入,也就是D键按下,程序获取到前进指令,那么获取到前进指令之后,马里奥是如何前进的呢,这篇文章我们重点讨论这个问题. 马里奥的移动,依旧是在帧刷新函数中,这个调用过程 ...
- IOS算法(三)之插入排序
直接插入排序(Insertion Sort)的基本思想是:每次将一个待排序的记录,按其keyword大小插入到前面已经排好序的子序列中的适当位置,直到所有记录插入完毕为止. 设数组为a[0-n-1]. ...
- cocos2dx的runAction: 反复运行,多个动作连接运行,多个动作同一时候运行的实现
cocos2dx的 runAction,假设某个动作重复运行用cc.RepeatForever:create, 多个动作连接运行用cc.Sequence:create,多个动作同一时候运行用cc.Sp ...
- android FragmentPagerAdapter的“标准”配置
private class ImagePagerAdapter extends FragmentPagerAdapter { public List<ImageItem> ...
- [Swust OJ 249]--凸包面积
题目链接: http://acm.swust.edu.cn/problem/0249/ 麦兜是个淘气的孩子.一天,他在玩钢笔的时候把墨水洒在了白色的墙上.再过一会,麦兜妈就要回来了, ...
- C++创建动态链接库(*.dll)
1. 从 “文件”菜单中,选择 “新建”,然后选择 “项目…”. 2. 在“项目类型”窗格中,选择“Visual C++”下的“Win32”. 3. 在“模板”窗格中,选 ...
- pl/sql 中F8执行单行sql
pl/sql中设置: tools->preferences->sql window->AutoSelect statement
- mysql版sql助记
新建用户 CREATE USER 'username'@'host' IDENTIFIED BY 'password'; [host 中 使用 % 为通配符, 匹配任意远程主机] 赋权 GRANT p ...
- B - 队列,推荐
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Desc ...