实现方式:
Serializable:
public class UserBean implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Parcelable:
public class PriceBean implements Parcelable {
private String shopName;
private int price;
public PriceBean() {
}
protected PriceBean(Parcel in) {
shopName = in.readString();
price = in.readInt();
}
public static final Creator<PriceBean> CREATOR = new Creator<PriceBean>() {
@Override
public PriceBean createFromParcel(Parcel in) {
return new PriceBean(in);
}
@Override
public PriceBean[] newArray(int size) {
return new PriceBean[size];
}
};
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(shopName);
dest.writeInt(price);
}
}
网友评论