Android very detailed serialization process parcelable

Source: Internet
Author: User

Directly on the code: the comments are written very clearly.

public class Entry implements parcelable{
public int UserID;
Public String username;
public Boolean Ismale;
Public book book;//serialization objects can nest serialized objects, provided that objects of 2 classes are
Returns 0 in almost all cases, regardless
@Override
public int describecontents () {
return 0;
}
Serializing objects, writing objects to the sequence Number data structure
Flags: Most cases are 0
@Override
public void Writetoparcel (Parcel out, int flags) {
Out.writeint (UserID);
Out.writestring (username);
Out.writeint (Ismale 1:0);
Out.writeparcelable (book, 0);
Out.writelist (list) or serial number list and map, provided that the data in the list and map are serial numbers
Out.writemap (MAP);
}
Public Entry (int userid,string Username,boolean ismale) {
This.userid = UserID;
This.username = Username;
This.ismale = Ismale;
}
Deserialization
public static final parcelable.creator<entry> Creator = new Creator<entry> () {
Creates an array of original objects of the specified length
@Override
Public entry[] NewArray (int size) {
TODO auto-generated Method Stub
return new Entry[size];
}
Create the original object from the object after the serial number
@Override
Public Entry Createfromparcel (Parcel source) {
TODO auto-generated Method Stub
return new Entry (source);
}
};
Create the original object from the object after the serial number
Private Entry (Parcel in) {
UserID = In.readint ();
Username = in.readstring ();
Ismale = in.readint () = = 1;
In.readparcelable (Thread.CurrentThread (). Getcontextclassloader ());
}

}

Android very detailed serialization process parcelable

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.