在onSaveInstanceState()
:
// departures is instance of Departures which extends ArrayList
bundle.putSerializable("departures", departures);
在onRestoreInstanceState
:
departures = (Departures) state.getSerializable("departures");
当我旋转屏幕时,Activity 会重新启动并恢复其状态。它工作正常。如果我离开 Activity,一段时间后,Android 会将其从内存中删除并保存其状态。当我返回它时,它会崩溃onRestoreInstanceState
:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to cz.fhejl.pubtran.Departures
现在getSerializable
回来了ArrayList
,没有Departures
。
编辑:这是 Departures.java 的外观: http: //pastebin.com/qc3QfrK7