Android Studio Excellent plugin (ii): Parcelable Code Generator

Source: Internet
Author: User

Android Studio Excellent plug-in series:

Android Studio Excellent plugin (i): Gsonformat

Android Studio Excellent plugin (ii): parcelable Code Generator

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

Parcelable, this word should be a stranger to you. An interface for serializing an object

Not clear can look at this blog: Intent the two methods of passing objects

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

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 classpeople implements parcelable {Private intID; PrivateString URL; Private intwidth; Private intheight; Private intLikecount; PrivateString description; Private intTime ; Private intReplycount; Private intFloorcount; Private intLikeusercount; Private intAge ; PrivateString name; PrivateString School; Private inttype; PrivateString sax; Private intuserid; @Override Public intdescribecontents () {return 0; } @Override Public voidWritetoparcel (Parcel dest,intflags) {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); }     Publicpeople () {}protectedPeople (Parcelinch) {         This. ID =inch. ReadInt ();  This. url =inch. readString ();  This. width =inch. ReadInt ();  This. Height =inch. ReadInt ();  This. Likecount =inch. ReadInt ();  This. Description =inch. readString ();  This. Time =inch. ReadInt ();  This. Replycount =inch. ReadInt ();  This. Floorcount =inch. ReadInt ();  This. Likeusercount =inch. ReadInt ();  This. Age =inch. ReadInt ();  This. Name =inch. readString ();  This. School =inch. readString ();  This. Type =inch. ReadInt ();  This. Sax =inch. readString ();  This. UserID =inch. ReadInt (); }     Public StaticFinal parcelable.creator<people> Creator =NewParcelable.creator<people>() {         Publicpeople Createfromparcel (Parcel source) {return Newpeople (source); }         PublicPeople[] NewArray (intsize) {            return NewPeople[size]; }    };}

Android Studio Excellent plugin (ii): 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.