The task is this: there are several fragments, in each - RecycleView .

It is necessary that when switching fragments in each fragment, the position of scrolling the list is maintained so as not to start from the beginning.

How is it more correct to implement architecturally, i.e. either all fragments are simultaneously stored in different containers, or somehow save their state and then replace into one container ... In general, it is not entirely clear ..

Fragments are switched via BottomNavigationView .

    1 answer 1

    Save to onPause() , restore to onResume()

    Preservation

     lastFirstVisiblePosition = ((LinearLayoutManager)recyclerView .getLayoutManager()) .findFirstCompletelyVisibleItemPosition(); 

    Recovery

     ((LinearLayoutManager) recyclerView.getLayoutManager()) .scrollToPositionWithOffset(lastFirstVisiblePosition,0) 

    Taken from here

    • Thank you, but if I understand correctly, does the example preserve / restore the position of the first fully visible element, and not the exact scrolling position? - Valery V.