SoFunction
Updated on 2025-03-11

Very detailed android serialization process Parcelable

This article shares the specific code of the Android serialization process Parcelable for your reference. The specific content is as follows

Directly upload 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;//Serialized objects can be nested with serialized objects, provided that both objects of the classes have been serialized by the serial number//Return 0 in almost all cases, you can ignore it@Override
public int describeContents() {
return 0;
}
//Serialize the object and write the object into the serial number data structure//flags: Most of the cases are 0@Override
public void writeToParcel(Parcel out, int flags) {
(userID);
(username);
(isMale ? 1:0);
(book, 0);
// (list); It can also have serial numbers list and map, provided that the data in the list and map are serial numbers// (Map);
}
public Entry(int userID,String username,boolean isMale) {
 = userID;
 = username;
 = isMale;
}
//Deserializationpublic static final <Entry> CREATOR = new Creator<Entry>() {
//Create an array of original objects of a specified length@Override
public Entry[] newArray(int size) {
// TODO Auto-generated method stub
return new Entry[size];
}
//Create the original object from the object with 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 sequence numberprivate Entry(Parcel in){
userID = ();
username = ();
isMale = () == 1;
(().getContextClassLoader());
}

}

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.