我正在使用onSaveInstanceState(Bundle outState)并在PutInt中传递一个int值,但在我的onActivitycreated方法中,当我尝试getInt然后它显示异常说,Key android:view_state期望Bundle但值是android.util .SparseArray。返回了默认值。
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mListView = getListView();
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
if (savedInstanceState !=null) {
mCheckedPosition = savedInstanceState.getInt(STATE_CHECKED_POSITION, -1);
}
..................
我在这里发送价值。这里很好。问题在于我什么时候得到它。
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_CHECKED_POSITION, mCheckedPosition);
Log.d(AppConstants.TAG,"STATE_CHECKED_POSITION"+mCheckedPosition );
}
答案 0 :(得分:1)
将int放入bundle后我会放super.onSaveInstanceState(outState);
。
'STATE_CHECKED_POSITION'的价值是什么?