在使用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序列化总结的更多相关文章

  1. Android中Parcelable接口

    1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...

  2. (转)Android中Parcelable接口用法

    1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...

  3. Android中Parcelable和Serializable接口用法

    1. Parcelable接口 Interface for classes whose instances can be written to and restored from a Parcel. ...

  4. Android中Parcelable与Serializable接口用法

    转自: Android中Parcelable接口用法 1. Parcelable接口 Interface for classes whose instances can be written to a ...

  5. Android中Parcelable接口的使用

    在做开发的过程中,序列化是非常常见的.比如要将对象保存本地磁盘或者在网络上传输等.实现序列化有两种方式,一种是实现Serializable接口,第二种是实现Parcelable. Serializab ...

  6. Android 使用Parcelable序列化对象

    转:http://ipjmc.iteye.com/blog/1314145       Android序列化对象主要有两种方法,实现Serializable接口.或者实现Parcelable接口.实现 ...

  7. Android中Parcelable的使用

    转载请标明出处 :https://www.cnblogs.com/tangZH/p/10998065.html  Parcelable与Serializable Serializable是Java为我 ...

  8. Android中Parcelable的原理和使用方法

    Parcelable的简单介绍 介绍Parcelable不得不先提一下Serializable接口,Serializable是Java为我们提供的一个标准化的序列化接口,那什么是序列化呢? 进行And ...

  9. Android中Parcelable接口用法

    from: http://www.cnblogs.com/renqingping/archive/2012/10/25/Parcelable.html Interface for classes wh ...

随机推荐

  1. MySQL Cluster-备份恢复初步测试

    参考文档   http://blog.chinaunix.net/uid-20639775-id-1617795.html  http://xxtianxiaxing.iteye.com/blog/5 ...

  2. Windows Azure 社区新闻综述(#77 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 ·   文章: Windows Azure 表存储简 ...

  3. boost库学习随记六:使用同步定时器、异步定时器、bind、成员函数回调处理、多线程的同步处理示例等

    一.使用同步定时器 这个示例程序通过展示如何在一个定时器执行一个阻塞等待. //makefile #-------------------------------------------------- ...

  4. easui tree载入时自动展开无子节点的节点

    利用loadFilter对后台返回的原始数据进行过滤处理,将数据中的state字段修改相应的值,若无子节点,则改成open,若有子节点,则改成closed. 由于一个node属性只有下面几项内容,因此 ...

  5. c++,内联成员函数

    内联成员函数有两程方式实现内联成员函数1)在声名成员函数的同时定义成员函数体2)声明成员函数时,在最前面加上inline关键字在定义成员函数时也在最前面加上inline关键字 建议inline函数在头 ...

  6. 如何设置gen_server在退出时执行相关操作

    如果gen_server在监控树中不需要stop函数,gen_server会由其supervisor根据shutdown策略自动终止掉.如果要在进程终止之前执行清理,shutdown策略必须设定一个t ...

  7. stdcall、cdecl、fastcall、thiscall 、naked call的汇编详解

    函数调用规范   当高级语言函数被编译成机器码时,有一个问题就必须解决:因为CPU没有办法知道一个函数调用需要多少个.什么样的参数.即计算机不知道怎么给这个函数传递参数,传递参数的工作必须由函数调用者 ...

  8. 基于visual Studio2013解决C语言竞赛题之0414特殊平方数

       题目 解决代码及点评 这道题依旧是通过for循环,遍历所有四位数,然后根据题目要求判断数的性质即可 /**************************************** ...

  9. VC++界面编程之--使用分层窗口实现界面皮肤

    使用分层界面来实现界面皮肤的好处是:可以保证图片边缘处理不失真,且能用于异形窗口上,如一些不规则的窗口,你很难用SetWindowRgn来达到理想效果. 在很多情况下,界面的漂亮与否,取决于PS的制作 ...

  10. 找唯一不出现三次而出现1次的数子O(n)位运算算法

    之前两次那个是异或运算处理.这次以为也是类似.可是没想出来. 高富帅想出来了算法,转为bitset,然后加起来 同样的话 要么0+0+0 要么1+1+1,最后剩下的 能够通过%3 算出0 或1.思想是 ...