Android Studio 优秀插件: Parcelable Code Generator
这里假设我们已经会使用 Parcelable 序列化一个对象了~~
那么大家会发现 Parcelable 使用起来有些复杂,因为我们要自己复写 几个方法,而且当类的属性比较多的时候,我们就会难受了,又要注意不写错属性名,又要注意写对属性的类型,又要花不少的时间做重复的事情。
那么因为 Parcelable 有使用它的优势,我们又不能放弃,那该怎么办么?
Android Studio 提供给了我们 一个插件用来简化 给一个类 实现 Parcelable 接口的流程。
-----------------------------------------------------------------------------
现在学习下如何使用这个插件:
1、Android Studio 打开一个项目,点击左上角 File -->Settings... 进行设置

2、选择插件Plugins , 搜索Parcel,如果你没有下载过这个插件,那么搜索框下面会显示“Nothing to show.Click Browse to....”
3、那就点击蓝色字体的 Browse 吧 ,这个时候会出现如下图的界面,我们只需要在左边选中arcel然后点击右面 绿色按钮 "Install plugin" 就可以了

4、完成了上面三个步骤,就可以使用Parcelable Code Generator插件了
怎么用呢,
(1)创建一个类文件,类名是看你需求自定义写的,添加上你需要的属性
(2)快捷键 alt+insert ,会出现如下选择框,选择Parcelable 即可

然后我们就看到代码,是不是比我们手动写要快的许多
public class People implements Parcelable {
private int id;
private String url;
private int width;
private int height;
private int likeCount;
private String description;
private int time;
private int replyCount;
private int floorCount;
private int likeUserCount;
private int age;
private String name;
private String school;
private int type;
private String sax;
private int userid;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.id);
dest.writeString(this.url);
dest.writeInt(this.width);
dest.writeInt(this.height);
dest.writeInt(this.likeCount);
dest.writeString(this.description);
dest.writeInt(this.time);
dest.writeInt(this.replyCount);
dest.writeInt(this.floorCount);
dest.writeInt(this.likeUserCount);
dest.writeInt(this.age);
dest.writeString(this.name);
dest.writeString(this.school);
dest.writeInt(this.type);
dest.writeString(this.sax);
dest.writeInt(this.userid);
}
public People() {
}
protected People(Parcel in) {
this.id = in.readInt();
this.url = in.readString();
this.width = in.readInt();
this.height = in.readInt();
this.likeCount = in.readInt();
this.description = in.readString();
this.time = in.readInt();
this.replyCount = in.readInt();
this.floorCount = in.readInt();
this.likeUserCount = in.readInt();
this.age = in.readInt();
this.name = in.readString();
this.school = in.readString();
this.type = in.readInt();
this.sax = in.readString();
this.userid = in.readInt();
}
public static final Parcelable.Creator<People> CREATOR = new Parcelable.Creator<People>() {
public People createFromParcel(Parcel source) {
return new People(source);
}
public People[] newArray(int size) {
return new People[size];
}
};
}
Android Studio 优秀插件: Parcelable Code Generator的更多相关文章
- Android项目实战(十九):Android Studio 优秀插件: Parcelable Code Generator
Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat Android Studio 优秀插件(二): Parcelable Code Gen ...
- Android开发实战(十八):Android Studio 优秀插件:GsonFormat
Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat Android Studio 优秀插件(二): Parcelable Code Gen ...
- Android Studio 优秀插件汇总
第一部分 插件的介绍 Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的 ...
- 拿走不谢!22 个 Android Studio 优秀插件汇总
Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的开发工具,还提供了第三 ...
- Android Studio 优秀插件:GsonFormat
作为一个Android程序猿,当你看到后台给你的json数据格式时: { "id":123, "url": "http://img.donever.c ...
- Android Studio优秀插件汇总
- Android Studio常用插件续
这个月因为各种事情在忙,包括赶项目,回老家,还有准备旅游的事,所以应该写不了四篇博客了.今天介绍一下关于Android Studio 的几个好用的插件,都是我在用的,它们或能帮你节省时间,或者让你心情 ...
- Android Studio/IDEA插件
1.android parcelable code generator 2.android code generator3.gson format4.android postfix completio ...
- Android Studio 实用插件整理
首先说一下安装方法: 上图片: 首先点击Android stuido 菜单 File->Settings 进入上图界面: 区域1:你当前已经安装了的插件 区域3:在线安装 区域2:其实和区域3是 ...
随机推荐
- lightoj 1028 - Trailing Zeroes (I)(素数筛)
We know what a base of a number is and what the properties are. For example, we use decimal number s ...
- Codeforces Round #383 (Div. 2)D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(dp背包+并查集)
题目链接 :http://codeforces.com/contest/742/problem/D 题意:给你n个女人的信息重量w和美丽度b,再给你m个关系,要求邀请的女人总重量不超过w 而且如果邀请 ...
- Catch That Cow POJ - 3278 [kuangbin带你飞]专题一 简单搜索
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. ...
- Bytes类型
Bytes类型 一.定义 bytes类型是指一堆字节的集合,在python中以b开头的字符串都是bytes类型. b'\xe5\xb0\x8f\xe7\x8c\xbf\xe5\x9c\x88' ''' ...
- Java日志框架总结
1. 前言 从写代码开始,就陆陆续续接触到了许多日志框架,较常用的属于LOG4J,LogBack等.每次自己写项目时,就copy前人的代码或网上的demo.配置log4j.properties或者lo ...
- 【Offer】[58-2] 【左旋转字符串】
题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部.请定义一个函数实现字符串左旋转操作的功能.比如,输入字符串"a ...
- Spring Boot与Spring MVC集成启动过程源码分析
开源项目推荐 Pepper Metrics是我与同事开发的一个开源工具(https://github.com/zrbcool/pepper-metrics),其通过收集jedis/mybatis/ht ...
- 阿里yum源与华为yum源的配置
如何使用华为云提供的CentOS镜像源(x86_64)? 更新时间: 2019/08/16 11:17 查看PDF 分享 微博 分享文档到微博 微信 扫码分享文档 ...
- zookeeper 单机. 集群环境搭建
zookeeper分布式系统中面临的很多问题, 如分布式锁,统一的命名服务,配置中心,集群的管理Leader的选举等 环境准备 分布式系统中各个节点之间通信,Zookeeper保证了这个过程中 数据的 ...
- JVM参数配置及详解 -Xms -Xmx -Xmn -Xss 调优总结
堆大小设置JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制;系统的可用虚拟内存限制;系统的可用物理内存限制.32位系统 下,一般限制在1.5G~2G;64为操 ...