序列化:

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);
反序列化:
Stack<Class<? extends WizardStep>> wizardSteps =
(Stack<Class<? extends WizardStep>>) getIntent().getExtras().getSerializable("WizardSteps");
异常(exception):

最佳答案

其已知的bug。我惊讶它仍然存在。

使用通用容器,例如:

public class SerializableHolder implements Serializable {
private Serializable content;
public Serializable get() {
    return content;
}
public SerializableHolder(Serializable content) {
    this.content = content;
 }
}

如果您使用GSON库,请将您的堆栈转换为字符串,并在不进行序列化的情况下用作 bundle 的单个字符串。它应该工作。

10-01 00:38