From: http://blog.sina.com.cn/s/blog_78e3ae430100pxba.html
Android provides a new type: parcel. This class is used as a container to encapsulate data. The encapsulated data can be transmitted through intent or IPC. Except for the basic type, only classes that implement the parcelable interface can be put into parcel. Parcelable Implementation points: three things need to be implemented. 1) The writetoparcel method. This method writes the data of the class to the external provided parcel. The declaration is as follows: for specific parameter meanings of writetoparcel (parcel DEST, int flags), see javadoc2) describecontents method. I don't understand what it is, but it can return 0 directly anyway. 3) Static parcelable. creator interface. This interface has two methods: createfromparcel (parcel in) to create a class instance from the in function newarray (INT size) to create a type of T, return New T [size. It is estimated that this method is used for external class deserialization of this class array. Activityimport android. app. activity; import android. content. intent; import android. OS. bundle; import android. OS. parcelable; public class test extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); intent I = getintent (); person P = I. getparcelableextra ("yes"); system. out. println ("---->" + P. name); system. out. println ("---->" + P. map. size () ;}} the activityimport Java. util. hashmap; import android. app. activity; import android. content. intent; import android. OS. bundle; public class testnew extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); intent = new intent (); person P = new person (); p. map = new hashmap <string, string> (); p. map. put ("yes", "Ido"); p. name = "OK"; intent. putextra ("yes", P); intent. setclass (this, test. class); startactivity (intent) ;}} implementation class of parcelable import Java. util. hashmap; import android. OS. parcel; import android. OS. parcelable; public class person implements parcelable {public hashmap <string, string> map = new hashmap <string, string> (); Public string name; @ override public int describecontents () {return 0 ;}@ override public void writetoparcel (parcel DEST, int flags) {DeST. writemap (MAP); DeST. writestring (name);} public static final parcelable. creator <person> creator = new parcelable. creator <person> () {// rewrite creator @ override public person createfromparcel (parcel source) {person P = new person (); p. map = source. readhashmap (hashmap. class. getclassloader (); p. name = source. readstring (); Return P ;}@ override public person [] newarray (INT size) {// todo auto-generated method stub return NULL ;}};
}