I am trying to save my Recyclerview's LinearLayoutManager state.
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"));
}
.....
....
}
But savedInstanceState
is always null.
I already tried to restore its state in the onCreate & onActivityCreated methods, but in vain. What am I doing wrong ?
I checked these questions to be certain that this is the correct way to save & restore :