连载:
Bundle activityArguments = new Bundle();
Stack<Class<? extends WizardStep>> wizardSteps = new Stack<Class<? extends WizardStep>>();
wizardSteps.push(CreatealarmStep5View.class);
wizardSteps.push(CreatealarmStep4View.class);
wizardSteps.push(CreatealarmStep3View.class);
wizardSteps.push(CreatealarmStep2View.class);
wizardSteps.push(CreatealarmStep1View.class);
activityArguments.putSerializable("WizardSteps", wizardSteps);
Deserialisation:
Stack<Class<? extends WizardStep>> wizardSteps =
(Stack<Class<? extends WizardStep>>) getIntent().getExtras().getSerializable("WizardSteps");
例外:
12-20 23:19:45.698:E / AndroidRuntime(12145):引起:java.lang.classCastException:java.util.ArrayList无法强制转换为java.util.Stack
解决方法:
它的知名度为bug.我很惊讶它仍然存在.
使用通用容器,如:
public class SerializableHolder implements Serializable {
private Serializable content;
public Serializable get() {
return content;
}
public SerializableHolder(Serializable content) {
this.content = content;
}
}
如果您使用GSON库,请将Stack转换为String并将其用作Bundle的单个String,而不使用Serialize.它应该工作.