欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

很詳細(xì)的android序列化過程Parcelable

 更新時間:2022年08月25日 17:07:46   作者:夏操  
這篇文章主要為大家詳細(xì)介紹了很詳細(xì)的android序列化過程Parcelable,代碼注釋很詳細(xì),感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android序列化過程Parcelable的具體代碼,供大家參考,具體內(nèi)容如下

直接上代碼:注釋都寫的很清楚了。

public class Entry implements Parcelable{
public int userID;
public String username;
public boolean isMale;
public Book book;//序列化對象可以嵌套序列化對象,前提是2個類的對象都被序列號過
//幾乎所有情況下都返回0,可以不管
@Override
public int describeContents() {
return 0;
}
//序列化對象,將對象寫到序列號數(shù)據(jù)結(jié)構(gòu)中
//flags:大多數(shù)情況為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);也可以序列號list和Map,前提是list和Map里面的數(shù)據(jù)都是可序列號的
// out.writeMap(Map);
}
public Entry(int userID,String username,boolean isMale) {
this.userID = userID;
this.username = username;
this.isMale = isMale;
}
//反序列化
public static final Parcelable.Creator<Entry> CREATOR = new Creator<Entry>() {
//創(chuàng)建指定長度的原始對象數(shù)組
@Override
public Entry[] newArray(int size) {
// TODO Auto-generated method stub
return new Entry[size];
}
//從序列號過后的對象中創(chuàng)建原始對象
@Override
public Entry createFromParcel(Parcel source) {
// TODO Auto-generated method stub
return new Entry(source);
}
};
//從序列號后的對象中創(chuàng)建原始對象
private Entry(Parcel in){
userID = in.readInt();
username = in.readString();
isMale = in.readInt() == 1;
in.readParcelable(Thread.currentThread().getContextClassLoader());
}

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論