Reference Blog http://blog.csdn.net/yangzl2008/article/details/7593226
Due to the project needs, the activity is to pass a particularly complex data structure object, because the previous serialization is directly using serializable, but serializable can not pass the complex data structure, view the method of the bundle, know parcelable
The use of parcelable looks complicated, but it is also quite simple, that is, using the Writetoparcel (Parcel Dest,int Flags) method to write the attributes in your class to the Parcel object, The Createfromparcel (Parcel in) of the creator is parsed when it is received.
The difficulty I encounter is that there are enumerated and multi-level list collections in the data structure:
Since the enum implements the serializable interface, it can be read through in.readserializable (), and the Enum object's. Ordinal () method gets the index of the enumeration value written to the parcel object, in In.readint ( ) and then parse out the enumeration values.
As for the serialization of the list collection It hurts me to say what I'm doing.
1.Parcelable There are two methods that are arraylist<myclass> list = In.readarraylist (ClassLoader); In.readlist (List, ClassLoader) This time involves the ClassLoader parameter settings, view the source code has a lot of ClassLoader choice, I chose a Serializable.class.getClassLoader (), and then the serialization result is a conversion error when the list collection is serialized into a number and then passed to the adapter in the next activity. This is not the way to solve the problem, but I think this method should be able to achieve, but where there are problems, not written right. If the reader has achieved this idea, we can communicate.
There is also a method in 2.Parcelable in.readtypedlist (recodelist,trainrecode.creator); The first parameter is the list collection for the output, and the second parameter is the creator static constant in the list child element class.
As a result of this method, the serialization is passed normally.
3. One way to see it on the StackOverflow is
List< object> myList = Span class= "KWD" >null; Parcel. Readlist (mylist,list . class. Getclassloader Category.mylist I'm using the List.class.getClassLoader () class loader, but I haven't tried it and I don't know if it works.
/span>
Note: One of them is writing writetoparcel (...) Methods and Createfromparcel (...) The parcel object is written and read in the same order as in the method, otherwise there will be an order exception and garbled characters.
Android parcelable serialization of complex data structures