I have 3 activities: A --> B --> C
In Activity B, I'm populating using RecyclerView's GridlayoutManager. I want to save the scrolled state when i navigate to Activity C and restore the scrolled state when i go back to Activity B from Activity C.
private RecyclerView mImgList;
private GridLayoutManager mRecyclerGridMan;
private final String KEY_RECYCLER_STATE = "recycler_state";
private Parcelable mListState = null;
private static Bundle mBundleRecyclerViewState;
.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
.
@Override
protected void onPause()
{
super.onPause();
mBundleRecyclerViewState = new Bundle();
mListState = mImgList.getLayoutManager().onSaveInstanceState();
mBundleRecyclerViewState.putParcelable(KEY_RECYCLER_STATE, mListState);
}
.
@Override
protected void onResume()
{
super.onResume();
if (mBundleRecyclerViewState != null) {
mListState = mBundleRecyclerViewState.getParcelable(KEY_RECYCLER_STATE);
mImgList.getLayoutManager().onRestoreInstanceState(mListState);
}
}
But this works when I press back button from Activity B and go to Activity A, and navigating back to Activity B from Activity A.