Attach a connection first, here is very detailed, thank the author http://www.cnblogs.com/renqingping/archive/2012/10/25/Parcelable.html
Examples of objects serialized with Parcelable are as follows, the Dest.writexx order in the Writetoparcel method is consistent with parcel.readxx in Createfromparcel, and must have public static in the class. Final parcelable.creator<phone> Creator, otherwise it throws an exception:
09-05 01:21:13.696:e/androidruntime (1049): java.lang.RuntimeException:Unable to start activity componentinfo{ Com.example.test2/com.example.test2.activitya}: Android.os.BadParcelableException:Parcelable protocol requires a Parcelable.creator object called Creator on class Com.example.test2.bean.Phone
Package Com.example.test2.bean;
Import Android.os.Parcel;
Import android.os.Parcelable;
public class Phone implements Parcelable {
public String model;
public float size;
public String manufacture;
Public Phone (string manufacture, string model, float size) {
This.manufacture = manufacture;
This.model = model;
this.size = size;
}
Public Phone (Parcel in) {
This.manufacture = In.readstring ();
This.model = In.readstring ();
This.size = In.readfloat ();
}
@Override
public int describecontents () {
return 0;
}
@Override
public void Writetoparcel (Parcel dest, int flags) {
Dest.writestring (manufacture);
Dest.writestring (model);
Dest.writefloat (size);
}
public static final parcelable.creator<phone> Creator = new Creator<phone> () {
@Override
Public Phone Createfromparcel (Parcel source) {
return new Phone (source);
}
@Override
Public phone[] NewArray (int size) {
return new Phone[size];
}
};
Public String toString () {
return manufacture + "," + Model + "," + Size + "inch";
}
}
Android Parcel First Knowledge