Serialisation:
Bundle activityArguments = new Bundle();
Stack> wizardSteps = new Stack
I hope am not talking any nonsense!
Stack does not implement Serializable but rather just extends the Serializable Vector
which is equivalent to ArrayList
I am unaware of the real definition of equivalent
and how loose could that be, but it is sufficient to say that the first super class of Stack that is Serializable is Vector.
Since we see this exception, then I would probably assume that casting the Serializable to ArrayList should not throw this exception. Otherwise, I am talking nonsense.
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.
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.