Java android:使用intent将可包裹对象从服务解析为活动时出现问题
我尝试使用AndroidJava android:使用intent将可包裹对象从服务解析为活动时出现问题,java,android,parcelable,Java,Android,Parcelable,我尝试使用AndroidIntent将Order对象详细信息参见下文)对象从Android服务(IntentService)传递到活动,我尝试了以下方法: 在服务类中: Bundle b = new Bundle(); b.putParcelable("lastOrder", serverResponse.getOrder()); 在活动中: Bundle resultData Order lastOrder = (Order) resultData.getParcelable("lastOr
Intent
将Order
对象详细信息参见下文)对象从Android服务(IntentService
)传递到活动,我尝试了以下方法:
在服务
类中:
Bundle b = new Bundle();
b.putParcelable("lastOrder", serverResponse.getOrder());
在活动中
:
Bundle resultData
Order lastOrder = (Order) resultData.getParcelable("lastOrder");
但我犯了以下错误:
public class Order implements Parcelable {
private Long order_id;
private String order_source;
private ArrayList<OrderItem> items;
private Shop shop;
.....
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeLong(order_id);
Bundle b = new Bundle();
b.putParcelableArrayList("OrderItems", items);
out.writeBundle(b);
// out.writeList(items);
out.writeParcelable(shop, 1);
}
public static final Parcelable.Creator<Order> CREATOR = new Parcelable.Creator<Order>() {
public Order createFromParcel(Parcel in) {
return new Order(in);
}
public Order[] newArray(int size) {
return new Order[size];
}
};
private Order(Parcel in) {
this.order_id = in.readLong();
Bundle b = in.readBundle(OrderItem.class.getClassLoader());
this.items = b.getParcelableArrayList("OrderItems");
//this.items = in.readArrayList(getClass().getClassLoader());
this.shop = in.readParcelable(Shop.class.getClassLoader());
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
public class Shop implements Parcelable {
private Long shop_id;
private String shop_date;
private String shop_code;
.....
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeLong(shop_id);
out.writeString(shop_date);
out.writeString(shop_code);
}
public static final Parcelable.Creator<Shop> CREATOR = new Parcelable.Creator<Shop>() {
public Shop createFromParcel(Parcel in) {
return new Shop(in);
}
public Shop[] newArray(int size) {
return new Shop[size];
}
};
private Shop(Parcel in) {
this.shop_id = in.readLong();
this.shop_date = in.readString();
this.shop_code = in.readString();
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
public class OrderItem implements Parcelable {
private Long order_item_id;
private Product product;
private ProductCategory product_Category;
private ArrayList<OrderExtra> extras;
.....
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeLong(order_item_id);
out.writeParcelable(product,1 );
out.writeParcelable(product_Category, 1);
//out.writeList(extras); http://androidideasblog.blogspot.com/2010/08/classnotfound-exception-when.html
Bundle b = new Bundle();
b.putParcelableArrayList("OrderExtras", extras);
out.writeBundle(b);
}
public static final Parcelable.Creator<OrderItem> CREATOR = new Parcelable.Creator<OrderItem>() {
public OrderItem createFromParcel(Parcel in) {
return new OrderItem(in);
}
public OrderItem[] newArray(int size) {
return new OrderItem[size];
}
};
private OrderItem(Parcel in) {
this.order_item_id = in.readLong();
this.product = in.readParcelable(getClass().getClassLoader());
this.product_Category = in.readParcelable(getClass().getClassLoader());
//this.extras = in.readArrayList(getClass().getClassLoader());
Bundle b = in.readBundle(OrderExtra.class.getClassLoader());
this.extras = b.getParcelableArrayList("OrderExtras");
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
public class Product implements Parcelable {
private Long product_id;
private String product_date;
private String product_name;
.....
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeLong(product_id);
out.writeString(product_date);
out.writeString(product_name);
}
public static final Parcelable.Creator<Product> CREATOR = new Parcelable.Creator<Product>() {
public Product createFromParcel(Parcel in) {
return new Product(in);
}
public Product[] newArray(int size) {
return new Product[size];
}
};
private Product(Parcel in) {
this.product_id = in.readLong();
this.product_date = in.readString();
this.product_name = in.readString();
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
public class ProductCategory implements Parcelable {
private Long product_category_id;
private String product_category_date;
private String product_category_name;
.....
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeLong(product_category_id);
out.writeString(product_category_date);
out.writeString(product_category_name);
}
public static final Parcelable.Creator<ProductCategory> CREATOR = new Parcelable.Creator<ProductCategory>() {
public ProductCategory createFromParcel(Parcel in) {
return new ProductCategory(in);
}
public ProductCategory[] newArray(int size) {
return new ProductCategory[size];
}
};
private ProductCategory(Parcel in) {
this.product_category_id = in.readLong();
this.product_category_date = in.readString();
this.product_category_name = in.readString();
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
public class OrderExtra implements Parcelable {
private Long order_item_extra_id;
private String order_item_extra_price;
private String order_item_extra_name;
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeLong(order_item_extra_id);
out.writeString(order_item_extra_price);
out.writeString(order_item_extra_name);
}
public static final Parcelable.Creator<OrderExtra> CREATOR = new Parcelable.Creator<OrderExtra>() {
public OrderExtra createFromParcel(Parcel in) {
return new OrderExtra(in);
}
public OrderExtra[] newArray(int size) {
return new OrderExtra[size];
}
};
private OrderExtra(Parcel in) {
this.order_item_extra_id = in.readLong();
this.order_item_extra_price= in.readString();
this.order_item_extra_name= in.readString();
}
}
公共类订单实现可包裹{
私人长订单id;
私有字符串顺序_源;
私有ArrayList项;
私人店铺;
.....
@凌驾
公共无效写入包(包出,内部标志){
out.writeLong(订单号);
Bundle b=新Bundle();
b、 putParcelableArrayList(“订单项”,项目);
out.writeBundle(b);
//外写列表(项目);
可书面强制执行(商店,1);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共秩序createFromParcel(包裹中){
返回新订单(在中);
}
公共秩序[]新数组(整数大小){
返回新订单[大小];
}
};
私人订单(包裹寄送){
this.order_id=in.readLong();
Bundle b=in.readBundle(OrderItem.class.getClassLoader());
this.items=b.getParcelableArrayList(“OrderItems”);
//this.items=in.readArrayList(getClass().getClassLoader());
this.shop=in.readParcelable(shop.class.getClassLoader());
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
公共类商店实现可包裹{
私家长铺;;
私家弦店(星期日);
私有字符串存储单元代码;
.....
@凌驾
公共无效写入包(包出,内部标志){
out.writeLong(车间标识);
注销登记(营业日期);
out.writeString(车间代码);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共商店createFromParcel(包裹中){
返回新店铺(在中);
}
公共商店[]新阵列(整数大小){
返回新店铺[大小];
}
};
私家店(包裹内){
this.shop_id=in.readLong();
this.shop_date=in.readString();
this.shop_code=in.readString();
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
公共类OrderItem实现了Parcelable{
私人长订单项目id;
私人产品;
私人产品类别产品类别;
私人ArrayList extras;
.....
@凌驾
公共无效写入包(包出,内部标志){
out.writeLong(订单项标识);
可写可执行(产品,1);
可写可执行(产品类别,1);
//外写列表(附加);http://androidideasblog.blogspot.com/2010/08/classnotfound-exception-when.html
Bundle b=新Bundle();
b、 putParcelableArrayList(“额外订单”,额外订单);
out.writeBundle(b);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
public OrderItem createFromParcel(中的包裹){
返回新的OrderItem(在中);
}
public OrderItem[]新数组(整数大小){
返回新的OrderItem[大小];
}
};
私人订单项目(包裹中){
this.order_item_id=in.readLong();
this.product=in.readParcelable(getClass().getClassLoader());
this.product_Category=in.readParcelable(getClass().getClassLoader());
//this.extras=in.readArrayList(getClass().getClassLoader());
Bundle b=in.readBundle(OrderExtra.class.getClassLoader());
this.extras=b.getParcelableArrayList(“OrderExtras”);
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
公共类产品实现了Parcelable{
私人长产品标识;
私有字符串产品_日期;
私有字符串产品名称;
.....
@凌驾
公共无效写入包(包出,内部标志){
out.writeLong(产品标识);
注销登记(产品登记日期);
out.writeString(产品名称);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共产品createFromParcel(包裹中){
退回新产品(在);
}
公共产品[]新数组(整数大小){
退回新产品[尺寸];
}
};
私人产品(包裹内){
this.product_id=in.readLong();
this.product_date=in.readString();
this.product_name=in.readString();
}
}
// // // // // // // // // // // // // // // // // // // // // // // // //
公共类ProductCategory实现了Parcelable{
私人长产品\类别\ id;
私有字符串产品\类别\日期;
私有字符串产品\类别\名称;
.....
@凌驾
公共无效写入包(包出,内部标志){
out.writeLong(产品类别标识);
注销登记(产品类别日期);
out.writeString(产品类别名称);
}
public static final Parcelable.Creator=新建Parcelable.Creator(){
公共产品类别