Saturday, June 4, 2011

[android-developers] Bundle.putSerializable not calling custom writeObject(ObjectOutputStream) method?

I get a StackOverflowError due to a deeply nested object structure I'm putting into the Bundle in onSaveInstanceState (compare http://stackoverflow.com/questions/438875/stackoverflowerror-when-ser...). 

To prevent this from happening I wrote custom writeObject/readObject methods for the one object causing the trouble (basically serializing it iteratively instead of recursively).

What happens is: 
- I rotate the phone 
- onSaveInstanceState() is called --> outState.putSerializable("key", myObject); 
- the custom writeObject method is NOT called 
- activity is destroyed and newly created 
- in onCreate(Bundle savedInstanceState) the object is restored but again without calling my custom readObject method 

I analyzed the Android code for Bundle, Parcel and ObjectOutputStream and IMHO it should invoke my custom methods but it doesn't. 

Any ideas how to make this work? 

And no it's not an option to write it as a Parcel instead, I would have to add the Parcelable code to around 100 classes.

Best Regards 

Emanuel Moecklin 

1gravity LLC

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment