在应用程序中,只要片段失去焦点(即在其上打开另一个活动/片段),就会调用onSaveInstanceState().
同样在developers guide中提到.
我试图使用这个approch来恢复我的片段的状态.
我的目的是在片段恢复时在onActivityCreated()中调用此包.
虽然在片段失去焦点之前调用onSaveInstanceState.
但是,当调用onActivityCreated()时,它会将Bundle savedInstanceState作为null返回.
如何从捆绑包中获取数据.
码:
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); MyListAdapter adapter = new MyListAdapter(getActivity(),R.layout.my_row,titles,icons,this); setListAdapter(adapter); if (savedInstanceState != null) { // Never goes inside this condiiton. // Restore last state for checked position. mCurCheckPosition = savedInstanceState.getInt("curChoice",0); } } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("curChoice",mCurCheckPosition); }