Activity 间传递对象, 采用Parcelable. 例子如下:
public class FormatEntity implements Parcelable {
public String mAccount;
public String mCode;
public int limitAmount;
public String imeis;
public PrivateFormatEntity() {
super();
}
public PrivateFormatEntity(Parcel source) {
mAccount = source.readString();
mCode = source.readString();
limitAmount = source.readInt();
imeis = source.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mAccount);
dest.writeString(mCode);
dest.writeInt(limitAmount);
dest.writeString(imeis);
}
public static final Parcelable.Creator<PrivateFormatEntity> CREATOR = new Creator<PrivateFormatEntity>() {
@Override
public PrivateFormatEntity[] newArray(int size) {
return new PrivateFormatEntity[size];
}
@Override
public PrivateFormatEntity createFromParcel(Parcel source) {
return new PrivateFormatEntity(source);
}
};
}
发送:
FormatEntity youFormat = new FormatEntity();
it.putExtra("yourname", youFormat);
获取:
it.getParcelableExtra("yourname");