ArrayList 是在类级别定义的。 这些是我保存的实例方法:
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putStringArrayList("savedList", list);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
list=savedInstanceState.getStringArrayList("savedList");
}
但是,当我改变方向时,ArrayList 仍然是空白
最佳答案
当您使用 onRestoreInstanceState()
恢复状态时,它会在 onStart()
之后调用,因此您可以在定义适配器后使用保存的状态更新列表。您最好的选择是在 onCreate()
中恢复列表,就像在 onRestoreInstanceState()
中一样。您还可以重新定义适配器或调用 notifyDataSetChanged()
。
关于android - 将 ArrayList 保存在 bundle savedInstanceState 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16264764/