我试图将数组列表的值存储在onSavedInstanceState()
并在 onCreate 方法中获取数组列表中的值,但它会引发类似无法暂停活动的错误
这是我的代码
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putParcelable("Old", (Parcelable) profileDetails );
super.onSaveInstanceState(savedInstanceState);
}
并在我的onCreate()
if (savedInstanceState != null) {
profileDetails= (ArrayList<ProfileDetails>)savedInstanceState.getParcelable("Old");
}
else {
profileDetails = GetSearchResults();
}
捆绑可以存储Serializable
对象也。
确保比你的class ProfileDetails implements Serializable
.
之后,您将能够使用以下命令在 Bundle 中保存/恢复 ArrayList:
savedInstanseState.putSerializable("Old", profileDetails);
...
profileDetails = (ArrayList<ProfileDetails>)savedInstanceState.getSerializable("Old");
另外你应该保证class ProfileDetails
仅包含原始类型或可序列化的字段(字符串、数组已实现此接口)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)