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 ());
}
}