Summary of Parcelable serialization in Android

Source: Internet
Author: User

It's still useful to use parcelable to serialize the data in Android, and someone has done it by comparing serializable and parcelable to the speed of serializing objects in Android, About Parcelable is about 10 times times faster than serializable 、、、 give a connection can look at their serialization differences http://greenrobot.me/devpost/android-parcelable-serializable/


The following is a summary of our basic data types, objects, arrays, lists and other ways to do parcelable, mainly to do a summary of the direct look at code

Package Com.suning.mobile.paysdk.pay;import Java.util.arraylist;import Android.os.parcel;import Android.os.parcelable;import com.yaya.test.orderinfobean;/** * *〈 A Word function brief description of 〉<br> *〈 function detail data type serialization */public class P    Arcelabletype implements parcelable {/** int type */int age;    /** String Type */String name;    /** Boolean Note that the get and set methods of the Boolean **/Boolean Isgood;    /** Boolean type **/boolean complete;    /** array **/private string[] IDs;    /** Object [internally serialized] **/private Orderinfobean bean;    /** list **/private arraylist<orderinfobean> Listbeans; /** * Default Construction method */Public Parcelabletype () {//TODO auto-generated constructor stubs} public Parcela    Bletype (Parcel in) {Readfromparcel (in);        }/*** * Default implementation */@Override public int describecontents () {//TODO auto-generated method stub    return 0; } @Override public void Writetoparcel (Parcel dest, int flags) {/** int written **/deSt.writeint (age);        /** String writes **/dest.writestring (name);        /** Boolean write **/dest.writeint (isgood? 1:0);        /** Boolean Write **/dest.writeint (complete 1:0);        The/** array is written to **/if (ids! = null) {dest.writeint (ids.length);        } else {dest.writeint (0);        } dest.writestringarray (IDs);        /** object written to **/dest.writeparcelable (bean, flags);    /** List Write **/dest.writelist (Listbeans); } @SuppressWarnings ("Unchecked") private void Readfromparcel (Parcel in) {/** int read out */age = In.readi        NT ();        /** STIRNG read out */name = In.readstring (); /** Boolean read-out */Isgood = (in.readint () = = 1)?        True:false; /** Boolean readout */complete = (in.readint () = = 1)?        True:false;        /** Array Readout */int length = In.readint ();        ids = new String[length];        In.readstringarray (IDS); /** Object read out */bean = In.readParcelable (OrderInfoBean.class.getClassLoader ());    /** List read out */Listbeans = In.readarraylist (OrderInfoBean.class.getClassLoader ()); public static final parcelable.creator<parcelabletype> Creator = new Parcelable.creator<parcelabletype> (        {Public Parcelabletype Createfromparcel (Parcel in) {return new Parcelabletype (in);        } public parcelabletype[] NewArray (int size) {return new parcelabletype[size];    }    };    public int getage () {return age;    public void Setage (int.) {this.age = age;    } public String GetName () {return name;    } public void SetName (String name) {this.name = name; }/** * Function Description: <br> *〈 function Detailed description 〉fastjson parsing required format */public boolean Isisgood () {return    Isgood;    The public void Setisgood (Boolean isgood) {this.isgood = Isgood;    } public boolean Iscomplete () {return complete; }   public void SetComplete ("Boolean complete") {This.complete = complete;    } public string[] GetIDs () {return IDs;    } public void Setids (string[] ids) {this.ids = IDs;    } public Orderinfobean Getbean () {return bean;    } public void Setbean (Orderinfobean bean) {This.bean = bean;    } public arraylist<orderinfobean> Getlistbeans () {return listbeans;    } public void Setlistbeans (arraylist<orderinfobean> listbeans) {This.listbeans = Listbeans; }}



Summary of Parcelable serialization in Android

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.