When using an android bundle, why does a serialised stack deserialise as an ArrayList?
Its known bug. I surprise that it still exists.
Use generic container like:
public class SerializableHolder implements Serializable {
private Serializable content;
public Serializable get() {
return content;
}
public SerializableHolder(Serializable content) {
this.content = content;
}
}
If you use GSON
library, convert your Stack to String and use as single String for Bundle without Serialize. It should work.
Just cast the serializable you retrieved from the bundle to a List, create a new Stack, and then add all the List items to the stack:
Serializable serializable = savedInstanceState.getSerializable("key");
List<Something> list = (List<Something>) serializable;
Stack<Something> stack = new Stack<Something>();
stack.addAll(list);
Why cast to List and not ArrayList you ask? Because if this is fixed in some Android version, you won't have a ClassCastException again.