我正在尝试保存Recyclerview的LinearLayoutManager状态。
Fragment.java:
@Override
public void onSaveInstanceState(Bundle outState) {
Log.i("frag", "onSaveInstanceState called");
super.onSaveInstanceState(outState);
outState.putParcelable("myState", mGridLayoutManager.onSaveInstanceState());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (savedInstanceState != null) {
Log.i(MainActivity.TAG, "restore called from createView");
mGridLayoutManager.onRestoreInstanceState(savedInstanceState.getParcelable("myState"));
}
.....
....
}
但savedInstanceState
始终为空。
我已经尝试在 onCreate &中恢复其状态 onActivityCreated 方法,但徒劳无功。我做错了什么?
我检查了这些问题,以确保这是正确的保存方式。恢复:
答案 0 :(得分:0)
在调用outstate.putParcelable()后尝试调用super.onSaveInstanceState(outstate)?
如果这不起作用,可以尝试在字符串中放一个字符串,看看它是否与mGridLayoutManager.onSaveInstanceState()失败有关?