gpt4 book ai didi

android - 保存 Hash map 的 ArrayList

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:08:15 25 4
gpt4 key购买 nike

在我的应用程序中,我想将数据保存在 savedInstanceState() .我想保存ArrayList<HashMap<String,String>> .到目前为止,我无法做到这一点。 这是困扰我的代码

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelableArrayList("places", (ArrayList<? extends Parcelable>) places);

}

恢复()方法

private void restore(Bundle savedInstanceState) {
// TODO Auto-generated method stub
//What should i do here! i have try many things but none of them is helping

}

最佳答案

由于 ArrayListHashMapStringSerializable,您可以使用 Bundle.putSerializableBundle.getSerializable

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("places", places);
}

private void restore(Bundle savedInstanceState) {
if (savedInstanceState != null) {
places = (ArrayList<HashMap<String,String>>) savedInstanceState.getSerializable("places");
}
}

此外,请确保您从 onRestoreInstanceStateonCreate 调用 restore

关于android - 保存 Hash map 的 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14924177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com