Android Studio 优秀插件(二): Parcelable Code Generator

Android Studio 优秀插件系列:

Android Studio 优秀插件(一):GsonFormat

Android Studio 优秀插件(二): Parcelable Code Generator

-----------------------------------------------------------------------------

Parcelable  , 这个词大家应该不陌生吧,用于序列化对象的一个接口

不清楚的可以看一下这篇博客:Intent传递对象的两种方法

-----------------------------------------------------------------------------

这里假设我们已经会使用 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];
        }
    };
}
时间: 2024-08-05 19:35:36

Android Studio 优秀插件(二): Parcelable Code Generator的相关文章

Android Studio 优秀插件: Parcelable Code Generator

这里假设我们已经会使用 Parcelable 序列化一个对象了~~ 那么大家会发现 Parcelable 使用起来有些复杂,因为我们要自己复写 几个方法,而且当类的属性比较多的时候,我们就会难受了,又要注意不写错属性名,又要注意写对属性的类型,又要花不少的时间做重复的事情. 那么因为 Parcelable 有使用它的优势,我们又不能放弃,那该怎么办么? Android Studio 提供给了我们 一个插件用来简化 给一个类 实现 Parcelable 接口的流程. ---------------

Android开发实战(十八):Android Studio 优秀插件:GsonFormat

原文:Android开发实战(十八):Android Studio 优秀插件:GsonFormat Android Studio 优秀插件系列: Android Studio 优秀插件(一):GsonFormat ------------------------------------------------------------------------------------------------------- 这几天没有活,于是乎整理了一些代码,顺便把一些一直在使用的东西也整理下,然后学

Android?Studio?优秀插件汇总

第一部分 插件的介绍 Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的开发工具,还提供了第三方插件的支持.让开发人员更快速更好的开发程序. 第二部分 插件的安装 in Android Studio: go to File → Settings → Plugins → Browse repositories and search for 插件名 or in Androi

拿走不谢!22 个 Android Studio 优秀插件汇总

Google 在2013年5月的I/O开发者大会推出了基于IntelliJ IDEA java ide上的Android Studio.AndroidStudio是一个功能齐全的开发工具,还提供了第三方插件的支持.让开发人员更快速更好的开发程序. 插件的安装 in Android Studio: go to File → Settings → Plugins → Browse repositories and search for 插件名 or in Android Studio: go to

Android Studio常用插件续

这个月因为各种事情在忙,包括赶项目,回老家,还有准备旅游的事,所以应该写不了四篇博客了.今天介绍一下关于Android Studio 的几个好用的插件,都是我在用的,它们或能帮你节省时间,或者让你心情愉悦. 还是老话,本文原创,转载请注明在CSDN博客上的出处: http://blog.csdn.net/maosidiaoxian/article/details/44992655 以下所有插件都可以在Idea的插件库中找到,如果你与我一样在Android Studio中无法搜索到任何插件的话,可

Android Studio自动化快速实现Parcelable接口序列化

1.在线安装 然后打开File -> Settings -> Pugins -> Browse Repositories 如下,输入android parcelable code generator搜索到直接下就行(但是你应该下载不成功,为啥呢,你懂得****,请看离线安装)! 2.离线安装,点击这里下载安装包 下载好了之后,打开File -> Settings -> Pugins -> Install plugin from disk,选择你刚刚下载到的.zip压缩包

Android Studio常用插件

Android Studio常用插件 转载请注明出处:http://blog.csdn.net/crazy1235/article/details/48598803 不得不承认,Android Studio越用越爽.其代码提示和搜索功能相当强大,非常智能.颜色.图片在布局和代码中可以实时预览. 开发的过程中使用一些插件可以事半功倍,下面介绍一些博主开发过程中常用到的一些as插件供大家参考. Android Studio常用插件 ButterKnife codota Genymotion 安装HA

Android Studio添加插件(Genymotion)

官方模拟器的龟速已让我们无力吐槽,幸好有genymotion这款逆天的Android虚拟机,它有着快速的开启速度,良好的交互界面.是Android开发必备的良品,甚至有些玩家已经用genymotion在电脑上玩Android游戏.今天就要和大家分享如何在Android Studio添加插件(Genymotion). 首先你要去genymotion 官网  https://www.genymotion.com,下载这两个文件 如图 然后 双击第一个文件安装,一直next即可(中间一些安装路径可以自

Android studio 使用心得(四)—android studio 多渠道打包(二)

Android studio 使用心得(四)—android studio 多渠道打包 这篇文章讲了一种打包方式.是直接在android studio 里面可视化操作,结合配置文件.我个人觉得严格上来讲是不完全正确的操作,因为配置文件里面的签名文件根本没有用到.但是,打出来的包绝对没问题的.这篇主要是介绍直接在dos命令里面使用gradle命令打包.两行命令,简单gradle clean ,gradle build. 1,配置文件还是和之前的一样,我才贴一次代码 ? 1 2 3 4 5 6 7