5

I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides getView()). This custom adapter uses as its backend a List<CustomObject>. The elements in this List are retrieved from the network, so I would like to save it in onSaveInstanceState(). However, I can't find a way to put a List<E> in a Bundle. I'm thinking this is a common task, saving a custom array in the instance state. How do other people do it?

Pentium10
  • 204,586
  • 122
  • 423
  • 502
Felix
  • 88,392
  • 43
  • 149
  • 167

1 Answers1

1

You can't serialize a List<E>, you need to transform to an Array and use that when you pass a serialized object. Then read out the array and transform into a list. See this questions, it's about sortedset serialization E also must be serializable.

Look into .toArray or putStringArray either putStringArrayList

Community
  • 1
  • 1
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • Thanks for your answer, it guided me to the right direction. I ended up casting my List to an ArrayList, which is serializable and works perfectly. You probably would've suggested the same thing if I had mentioned my `List` is actually instantiated as an `ArrayList`, but unfortunately I didn't. – Felix Jul 11 '10 at 11:08