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. caffe特征层可视化

    #参考1:https://blog.csdn.net/sushiqian/article/details/78614133#参考2:https://blog.csdn.net/thy_2014/art ...

  2. 【新特性】JDK1.7

    一.switch中可以使用字串 String s = "test";switch (s) { case "test" :   System.out.printl ...

  3. 如何在 Apache 里修改 PHP 配置

    当使用 PHP 作为 Apache 模块时,也可以使用 Apache 配置文件(例如:httpd.conf) 和 .htaccess 文件中的指令来修改 PHP 的配置 设定,不过需要有 " ...

  4. 11_vim

    vim编辑器 文本编辑器,字处理器linux重要哲学思想之一:使用纯文本格式来保存软件的配置信息,大多数情况下都是如此,而且一切皆文件此前学过nano,sed..nano入门简单,但功能简陋 vi:V ...

  5. 小程序之 fixed定位下scroll-view左右滚动失效

    红框为悬浮 左右可以滑动 效果如下⬇️ 悬浮把最外层position:fixed;top:0;这个时候上面的导航就可以悬浮 但是会出现左右滑动不了的情况 这是因为我没给设置宽度 这个时候我们把包着sc ...

  6. PowerDesigner概念(概念数据模型概述)

  7. The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration

    用过Mysql的人都知道,这个时区问题真个磨人的小妖精,哪天一忘记设置了就会出来磨磨你!!! 之前用的解决方法都是在Mysql的配置上添加与时区相关的配置,但是今天看到一篇博客:https://blo ...

  8. 【安卓进阶】LiveData

    最近参与到后端的工作中,虽然以前在工作中使用过PHP,但是这次使用的是Java,开发思路和方式有所不同.后端开发中,做接口也是需要处理大量的业务逻辑关系,同时一些事务之类的技术因素也要考虑好,在架设项 ...

  9. 详解MySQL中concat函数的用法(连接字符串)

    MySQL中concat函数 使用方法: CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意: 如果所有参数均为非二进制 ...

  10. GT sport赛道详解 - Dragon Trail | 龙之径

    参考:GT sport所有赛道简介 今天的心情变化挺大,从绝望放弃到豁然开朗. 前言:GT sport有个排位赛,是每位sim赛车手提升自己等级的唯一途径,其中一个排位赛就是龙之径II(逆时针跑),我 ...