Take the 2-minute tour ×  I have a member variable in my
Activity which is an ArrayList. The objects populating this
ArrayList are objects I have defined called RatingItem.
RatingItem has several member vars like rating, comment, id,
etc.  I would like to save this ArrayList in onSaveInstanceState
so it can be repopulated from onRestoreInstanceState. What is
the best way to do this? I've never saved the state of an object
of this complexity.  Thank you for your help  share|improve this
question add comment  2 Answers  up vote 2 down vote accepted
You should probably have your object implement Parcelable.
Basically, you have to add methods to write and read the members
of your object from a Parcel, and then add custom CREATOR inner
class that has a couple of static factory methods. There's a
demo of it on the first linked page, but it's not too hard.
Then you can just save the whole list in one go with
Bundle.putParcelableArrayList(). (You'll have to cast the list
when you get it back out with Bundle.getParc