Android has a detailed serialization process of Parcelable and androidparcelable.

Source: Internet
Author: User

Android has a detailed serialization process of Parcelable and androidparcelable.

Directly go to the Code: The comments are clearly written.

Public class Entry implements Parcelable {
Public int userID;
Public String username;
Public boolean isMale;
Public Book book; // serialized objects can be nested with serialized objects, provided that the objects of both classes have been
// Return 0 in almost all cases.
@ Override
Public int describeContents (){
Return 0;
}
// Serialize the object and write it to the serial number Data Structure
// Flags: 0 in most cases
@ 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); you can also list the serial numbers and Map, provided that the data in list and Map are sequential 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> (){
// Create an array of original objects with 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 ());
}

}

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.