概述
生成实现了Parcelable接口的代码的插件
下载安装
1.在线安装
输入 Android Parcelable code generator ,点击安装即可,安装之后 重启,会看到上图选中部分所示。
2.手动下载安装
https://github.com/mcharmas/android-parcelable-intellij-plugin
使用
在你的类中,按下alt + insert键弹出插入代码的上下文菜单,会看到在下面有一个Parcelable,选择它之后,就会在你的类当中插入实现了Parcelable接口的代码了。
网络异常,图片无法展示
|
经验证,勾选Product的3个变量 和不选,生成的代码是一样的。
代码如下(setter+getter是之前已经写好了的)
package com.turing.base.activity.test; import android.os.Parcel; import android.os.Parcelable; /** * MyApp * * @author Mr.Yang on 2016-04-13 22:32. * @version 1.0 * @desc */ public class Product implements Parcelable { private int id; private String name; private float price; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public float getPrice() { return price; } public void setPrice(float price) { this.price = price; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.id); dest.writeString(this.name); dest.writeFloat(this.price); } public Product() { } protected Product(Parcel in) { this.id = in.readInt(); this.name = in.readString(); this.price = in.readFloat(); } public static final Creator<Product> CREATOR = new Creator<Product>() { @Override public Product createFromParcel(Parcel source) { return new Product(source); } @Override public Product[] newArray(int size) { return new Product[size]; } }; }