Android Studio Excellent plugin: parcelable Code Generator

Source: Internet
Author: User

This assumes that we are already using parcelable to serialize an object ~ ~

Then we will find that parcelable is a bit complicated to use, because we have to make a few of our own methods, and when the properties of the class is more, we will be uncomfortable, but also pay attention to not write the wrong attribute name, but also pay attention to write the type of property, but also spend a lot of time to do the repetitive things.

So because Parcelable has the advantage of using it, we can't give up, what should we do?

Android Studio provides us with a plugin to simplify the process of implementing a parcelable interface to a class.

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

Now learn how to use this plugin:

1, Android Studio open a project, click on the upper left corner File-->settings ... To set

2, choose Plug-in plugins, search parcel, if you have not downloaded this plugin, then the search box will show "Nothing to show." Click Browse to ....

3, then click on the blue font of the Browse bar, this time will appear as the interface, we just need to select Arcel on the left and then click on the Right green button "Install plugin" on it.

4, completed the above three steps, you can use the Parcelable Code generator plug-in

How to use it,

(1) Create a class file, the class name is to see what you need to customize the write, add the attributes you want

(2) shortcut key Alt+insert, will appear the following selection box, select Parcelable can

And then we see the code, is not much faster than we write manually

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 Excellent plugin: parcelable Code Generator

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.