There is a list of items, by clicking on one of them, I turn into a specific fragment, but when I click back, it returns not quite to that page (and to the last / active month ), I will explain here, there are several pages divided by months (in which there are different lists with the elements on which I click).
How before clicking on an item to track the state of the page (fragment) with which I click? In English, this sounds better.)
For this purpose I currently use this method.
fun Activity?.addFragment(fragment: Fragment?) { if (this == null || fragment == null) return try { fragmentManager.beginTransaction().replace(R.id.container, fragment, fragment.createTagName()) .addToBackStack(null).commit() } catch (ignored: IllegalStateException) { } } but how to track ( save the page ) the previous fragment I think you need to call this method.
currentPageIndexinto the fragment from which you click on the element and then check which index is on this page. If you would have something like typing text into views, then yes, it would make sense to save the state of the fragment, and I think so by. - Morozov