publicclasspushimplementsParcelable{ private String Name; private String Age; publicvoidSetName(String name){ Name = name; } public String GetName(){ return Name; } publicstatic Parcelable.Creator<push> CREATOR = new Creator<push>() {
@Override public push createFromParcel(Parcel source){ push test = new push(); test.setAge(source.readString()); test.SetName(source.readString()); return test; }
@Override public push[] newArray(int size) { returnnull; } }; @Override publicintdescribeContents(){ return0; } @Override publicvoidwriteToParcel(Parcel dest, int flags){ dest.writeString(Age); dest.writeString(Name); } public String getAge(){ return Age; } publicvoidsetAge(String age){ Age = age; } }
发送端接收端不变,和我们序列化的时候操作是一样的,这里稍微有一写要说的。
必须要有个静态成员public static Parcelable.Creator<push> CREATOR = new Creator<push>()然后实现里面的两个方法