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. word模板导出的几种方式:第二种:C#通过模板导出Word(文字,表格,图片) 占位符替换

    原文出处:https://www.cnblogs.com/ilefei/p/3508463.html 一:模板的创建   (注意文件后缀只能是.docx或.doct) 在需要位置 插入-文档部件-域, ...

  2. objectarx 把当前图形输出

    方法1: AcDbDatabase *pdb; acdbCurDwg()->wblock(pdb); pdb->saveAs(str); pdb->closeInput(true); ...

  3. windows cannot find powershell.exe windows 7

    This can happen when the environment variables are missing an entry for Powershell. $env:path must i ...

  4. 论文笔记:Learning Attribute-Specific Representations for Visual Tracking

    Learning Attribute-Specific Representations for Visual Tracking AAAI-2019 Paper:http://faculty.ucmer ...

  5. 集训队日常训练20181201 C 1003 : 种类数

    时间限制(普通/Java):2000MS/6000MS     内存限制:65536KByte总提交: 8            测试通过:5 描述 一共有 n个数,第 i 个数是 xi ,其中xi  ...

  6. winform使用log4.net

    因为我最近负责的Winform项目,好多都用到了这个log4net的日志功能,开发程序对数据一般都要求做到雁过留痕,所以日志对于我们程序员是不可或缺.因此我把对log4net的使用做一个记录总结,以便 ...

  7. postman(十一):添加cookie

    有些接口在调用时,需要提供权限,如下 这个时候可以通过添加cookie的方式跳过验证 为了更方便地获取cookie等信息,可以在chrome中安装一个插件:Postman Interceptor,配合 ...

  8. Mac安装python3.x+pycharm+elasticsearch+常见报错处理(1)

    ---恢复内容开始--- mac安装python有两种方式:此处叙述官网安装下载. mac 自带python2.x版本,python2和3之间的差距还是有的.下面简单叙述我安装python3.7的过程 ...

  9. RTK与差分测量的区别

    差分GPS定位原理 它使用一台 GPS基准接收机(基准站)和一台用户接收机(移动站),利用实时或事后处理技术,就可以使用户测量时消去公共的误差源 —卫星轨道误差.卫星钟差.大气延时.多路径效应.特别提 ...

  10. 调用 CURL 使用正则抓取信息

    Class MyCurl{  protected $_pdo;     //构造方法 链接数据库  public function __construct(){      $this->_pdo ...