最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

很詳細的android序列化過程Parcelable

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

本文實例為大家分享了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é)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

齐河县| 岳普湖县| 宜春市| 阳山县| 静乐县| 阿拉善右旗| 手机| 彭山县| 贡嘎县| 镇安县| 乐平市| 社旗县| 和龙市| 抚顺市| 英德市| 舒城县| 手机| 綦江县| 丘北县| 金堂县| 枞阳县| 大同县| 无锡市| 靖西县| 云龙县| 黄浦区| 四川省| 河池市| 石首市| 大悟县| 清流县| 牡丹江市| 巴东县| 连江县| 郎溪县| 海宁市| 肇州县| 邢台县| 河曲县| 图片| 双牌县|