I'm using the Navigation Component with a BottomNavigationView in my app. It switches between 4 destinations one of which contains a fragment with a RecyclerView containing hundreds of items. When I use the back button the RecyclerView restores with the previous scroll position. But When I use BottomNavigationView to switch between destinations, It won't restore to previous position and resets to the top of RecyclerView. Here's the code I tried to prevent that
override fun onPause() {
super.onPause()
lastScrollPos = linearLayoutManager.findFirstVisibleItemPosition()
}
override fun onResume() {
super.onResume()
card_recyclerView.layoutManager?.scrollToPosition(lastScrollPos)
}
This is not workign what is the best way of restoring RecyclerView to correct position?