1

更新:包括实际代码

我正在使用 ArrayList 填充自定义适配器,它在方向更改等方面工作正常:

“创建”

myArrayList = savedInstanceState.getParcelableArrayList(myListkey);

“onSaveInstanceState”

savedInstanceState.putParcelableArrayList(myListkey, myArrayList);

我可以把它弄出来

但是..我需要传递多个变量然后它会中断,看起来它只是我能得到的最后一个插入的变量。

例 1

“创建”

myNameString = savedInstanceState.getString(namekey);
myArrayList = savedInstanceState.getParcelableArrayList(myListkey);

“onSaveInstanceState”

savedInstanceState.putString(listkey, myNameString);
savedInstanceState.putParcelableArrayList(myListkey, myArrayList);

这里“myArrayList”已填充,但“myNameString”为空


前任。2

“创建”

myArrayList = savedInstanceState.getParcelableArrayList(listkey);
myNameString = savedInstanceState.getString(namekey);

“onSaveInstanceState”

savedInstanceState.putParcelableArrayList(listkey, myArrayList);
savedInstanceState.putString(namekey, myNameString);

此处“myNameString”已填充,但“myArrayList”为空


原始代码:

@Override
protected void onCreate(Bundle savedInstanceState) {

if (savedInstanceState != null) {
_listName = savedInstanceState.getString(getApplicationContext().getResources().getString(R.string.saved_instance_list_name));
_listItems = savedInstanceState.getParcelableArrayList(getApplicationContext().getResources().getString(R.string.saved_instance_list_items_edit));
 }

 ... more code

 }


@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);

    savedInstanceState.putString(getApplicationContext().getResources().getString(R.string.saved_instance_list_name), _listName);
    savedInstanceState.putParcelableArrayList(getApplicationContext().getResources().getString(R.string.saved_instance_list_items_edit), _listItems);

}
4

0 回答 0