读书人

Activity 间传送对象, 采用Parcelable

发布时间: 2012-09-06 10:37:01 作者: rapoo

Activity 间传递对象, 采用Parcelable

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");

读书人网 >移动开发

热点推荐