2017-08-14 21:23:34

一个较为复杂的Parcelable实现类

 public class CommentShareBean implements Parcelable {
/**
* 提示文案
*/
public String shareTitle;
/**
* 商家名称
*/
public String poiName;
/**
* 商家icon
*/
public String poiIcon;
/**
* 订单评分
*/
public int commentScore;
/**
* 评论
*/
public String commentContent;
/**
* 赞商品
*/
public List<PraiseFood> praiseFoodList;
/**
* 生成二维码的url
*/
public String poiShareUrl;
/**
* slogan(icon+文案)
*/
public String mtSlogan;
/**
* 二维码分享文案
*/
public String urlTip;
/**
* 可分享 道[1,2] 1:微信朋友圈 2:微信好友 3:qq空间 4:qq好友
*/
public List<Integer> channels; public CommentShareBean() { } private CommentShareBean(Parcel in) {
shareTitle = in.readString();
poiName = in.readString();
poiIcon = in.readString();
commentScore = in.readInt();
commentContent = in.readString();
if (in.readByte() == (byte) 1) {
PraiseFood[] foods = in.createTypedArray(PraiseFood.CREATOR);
praiseFoodList = Arrays.asList(foods);
}
poiShareUrl = in.readString();
mtSlogan = in.readString();
urlTip = in.readString();
if (in.readByte() == (byte) 1) {
int[] chas = in.createIntArray();
channels = new ArrayList<>();
for (int i = 0; i < chas.length; i++) {
channels.add(chas[i]);
}
}
} @Override
public int describeContents() {
return 9887;
} @Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(shareTitle);
dest.writeString(poiName);
dest.writeString(poiIcon);
dest.writeInt(commentScore);
dest.writeString(commentContent);
if (praiseFoodList != null && praiseFoodList.size() > 0) {
dest.writeByte((byte) 1);
PraiseFood[] ps = new PraiseFood[praiseFoodList.size()];
for (int i = 0; i < praiseFoodList.size(); i++) {
ps[i] = praiseFoodList.get(i);
}
dest.writeTypedArray(ps, 0);
} else {
dest.writeByte((byte) 0);
}
dest.writeString(poiShareUrl);
dest.writeString(mtSlogan);
dest.writeString(urlTip);
if (channels != null && channels.size() > 0) {
dest.writeByte((byte) 1);
int[] chas = new int[channels.size()];
for (int i = 0; i < channels.size(); i++) {
chas[i] = channels.get(i);
}
dest.writeIntArray(chas);
} else {
dest.writeByte((byte) 0);
}
} public static final Creator<CommentShareBean> CREATOR = new Creator<CommentShareBean>() {
@Override
public CommentShareBean createFromParcel(Parcel source) {
return new CommentShareBean(source);
} @Override
public CommentShareBean[] newArray(int size) {
return new CommentShareBean[size];
}
}; public static class PraiseFood implements Parcelable {
public String foodName; public PraiseFood(String name) {
foodName = name;
} public PraiseFood(Parcel in) {
foodName = in.readString();
} @Override
public int describeContents() {
return 12345;
} @Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(foodName);
} public static final Parcelable.Creator<PraiseFood> CREATOR = new Parcelable.Creator<PraiseFood>() { @Override
public PraiseFood createFromParcel(Parcel source) {
return new PraiseFood(source);
} @Override
public PraiseFood[] newArray(int size) {
return new PraiseFood[size];
}
};
}
}

较为复杂的实现Parcelable的子类--推荐Android中使用的更多相关文章

  1. Android中Serializable和Parcelable序列化对象详解

    学习内容: 1.序列化的目的 2.Android中序列化的两种方式 3.Parcelable与Serializable的性能比较 4.Android中如何使用Parcelable进行序列化操作 5.P ...

  2. 强烈推荐android studio用的几个插件

    http://blog.csdn.net/liang5630/article/details/46366901 android studio常用插件,可极大简化开发,增强开发效率. 不懂安装studi ...

  3. 强烈推荐android studio用的几个插件,androidstudio

    不懂安装studio插件,看参考博文:android stuido插件安装:http://blog.csdn.net/liang5630/article/details/46372447 1.Butt ...

  4. Android中Parcelable接口

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

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

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

  6. Android中Parcelable和Serializable接口用法

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

  7. Android中Parcelable与Serializable接口用法

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

  8. Android中的Parcelable接口和Serializable使用方法和差别

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

  9. Android中如何使用Intent在Activity之间传递对象[使用Serializable或者Parcelable]

    http://blog.csdn.net/cjjky/article/details/6441104 在Android中的不同Activity之间传递对象,我们可以考虑采用Bundle.putSeri ...

随机推荐

  1. 函数def

    函数:把执行一定功能的动作封装到一起>>> def 函数名(形参)      通过一个    函数名(实参)         去调用它,传参来执行功能.动作,输出结果 .定义:def ...

  2. Educational Codeforces Round 48 (Rated for Div. 2)

    http://codeforces.com/contest/1016 A. 没想到这个也会TLE,太粗心了 B. 暴力就好了,多情况讨论又出错... 思路跟我一样的解法   为什么我做了那么多讨论,原 ...

  3. windows中cmd常用命令收集

    1.经常会启动端口后忘关,需要杀端口的命令:查找端口占用命令 netstat -ano|findstr 端口例如      (8081)      杀端口: taskkill /pid xxxxx - ...

  4. Java 处理word文档后在前端展示

    最新新开发的这个项目需要使用word文档并要求能在前端页面上带格式展示,由于项目不是内部使用,所以不考虑插件类的处理模式,都必须要本地处理完成,前端不需要做什么更新或者说安装就能直接访问,类似于百度文 ...

  5. 微信小程序外包 就找北京动软 专业承接微信小程序定制

    很多人问为什么要开发微信小程序,微信小程序的“入口”在哪儿? 1.只有访问过的小程序,才会出现所谓的「入口」. 所有访问过得小程序都可以从微信首屏下面的「发现」点过去.(必须是最新版微信) 这个所谓的 ...

  6. 《Spring技术内幕》读书笔记

    简介: 1.spring 与unix.window这些操作在计算机系统中起到的作用是类似的 2.两大核心模块:IOC\AOP 3.为应用开发提供了许多现成的系统组件:事务处理.Web MV.JDBC. ...

  7. Devexpress中文语言包汉化

    1.下载对应版本的dev语音包 将语言包解压,放到如下文件夹,编译时会自动复制到bin目录下的. C:\Program Files (x86)\DevExpress 17.2\Components\B ...

  8. String、StringBuilder和StringBuffer的区别

    1         String.StringBuilder和StringBuffer的区别 String.StringBuilder.StringBuffer都可以用来保存字符串.如果是使用次数比较 ...

  9. Go语言学习之12 etcd、contex、kafka消费实例、logagent

    本节内容:    1. etcd介绍与使用    2. ElastcSearch介绍与使用 1. etcd介绍与使用    概念:高可用的分布式key-value存储,可以使用配置共享和服务发现    ...

  10. 持续集成CI/CD

    Gitlab+kubernetes+docker+jenkins+harbor搭建持续交付系统 http://blog.chenmiao.cf/2016/12/28/gitlab+kubernetes ...