I have migrated from ViewPager to ViewPager2
Official guide & blog are helpful.
But I found that my code working in one of the pages (Fragment) of the ViewPager, located inside onResume is not being executed, when I come back to the Fragment hosting TabLayout & ViewPager.
If I change Tabs, onResume is correctly called.
I am using navigation controller of JetPack where ViewPager2 is second fragment & I am coming back from a regular third fragment. I am returning to the page from where I had called third fragment. So it is a simple back.
viewPager.setOffscreenPageLimit(tabLength)
is in place, so that all tabs are loaded in one go.
Also have viewPager.isSaveEnabled = false
which loads the fragment in state as it was left, well preserved.
Have tried tab SelectedListener. But it is not called on back
tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
// not called on back
}
}
My need is to trigger a function call on back for just one particular page, of ViewPager2