spicecoder / tree-view-list-android

Automatically exported from code.google.com/p/tree-view-list-android
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

StackOverflow error when saving manager state #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My treeview is big (500 nodes and more) and I have a problem saving it state 
when screen orientation is changed. I use code from treeview demo in 
onSaveInstanceState event: 

outState.putSerializable("treeManager", manager);

Everything is ok while my tree is about 270 nodes or less. But when tree is 
bigger, then I get StackOverflow error here. Where may be a problem?

Original issue reported on code.google.com by DmLa...@gmail.com on 19 Feb 2012 at 6:56

GoogleCodeExporter commented 9 years ago
This is apparently a bug in androd/java serialisation (it is done by underlying 
java writeObject). You have a very long list of children. 
You can find the bug described here: 
http://bugs.sun.com/view_bug.do?bug_id=4152790 and (better explanation) 
http://stackoverflow.com/questions/438875/stackoverflowerror-when-serializing-an
-object-in-java . 

What you need to do is to write your own, custom serialization for the list of 
children -> instead of using default serialization define something like 
"MyOwnBetterSerializableList" with writeObject/readObject  methods defined..... 
I have also found interesting discussion from someone who tried to do it and 
had problem with custom write/read not called by Android (it seems that Android 
does not ALWAYS call serialize/deserialize - only when it is really needed, 
sometimes it will simply pass the object) : 
http://markmail.org/message/nlythcrqmepey2xv#query:+page:1+mid:vx3o3j5ozvm3zw5i+
state:results 

Speaking of the solution - This is really a weird edge case - I cannot really 
see how such a long list might be really usable on Android device (scrolling 
through list of 500 entries). Probably it calls for completely different user 
interface.  
So I won't make a fix for that, however this is a nice, separate piece of code 
to write - If you would like to make that fix - make a clone and make a 
patch/pull request so that I can incorporate that in my code.

Original comment by ja...@potiuk.com on 19 Feb 2012 at 8:13

GoogleCodeExporter commented 9 years ago
Ok, thank you for such a detailed answer. I'll think another solution (or may 
be own serialization methods).
What about long tree with 500 nodes - it is the users desire, but I think about 
possibility interface's reorganization too.

Original comment by DmLa...@gmail.com on 19 Feb 2012 at 2:49

GoogleCodeExporter commented 9 years ago
You're welcome... I know sometimes the customer says "it has to be done this 
way" even if this is pretty much unusable. Rather than having tree view, if 
there are lots of records to display, I would do it in the way that you have 
only one level (on a branch of tree) displayed at a time. When you go the lower 
level (drill down) you animate the higher level out (to the left) and at the 
same time animate the lower level in (from right). Revers when drill up.

Original comment by ja...@potiuk.com on 19 Feb 2012 at 2:56