public class Person implements Parcelable{
private String name;
private String phone;
//必须包含一个类型为Parcelable.Creator且名为CREATOR的公共静态成员
private static final Parcelable.Creator<Person> CREATOR = new Parcelable.Creator<Person>() {
@Override
public Person createFromParcel(Parcel source) { //该方法用于告诉平台如何从包裹里创建数据类实例
return new Person(source);
}
@Override
public Person[] newArray( int size) {
return new Person[size];
}
};
public Person(String name,String phone){
this .name = name;
this .phone = phone;
}
public Person(Parcel in){
this .name = in.readString();
this .phone = in.readString();
}
@Override
public int describeContents() {
return 0 ;
}
/**
* 告诉平台如何将数据实例写入Parcel里
*/
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString( this .getName());
dest.writeString( this .getPhone());
}
/**
* 属性的set和get方法
* @return
*/
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this .phone = phone;
}
}
|