Since API 27 FragmentPagerAdapter
is deprecated. What\'s the best alternative to use for this?
In my case, I understand something like super(fragm
Replace:
class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager)
with:
class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)
(assuming that MyViewPagerAdapter
does not need this value to be configurable)
It seems like not only the constructor without behavior, but the class FragmentPagerAdapter (which can consume a good amount of memory by keeping Framents in memory), and FragmentStatePagerAdapter are both in deprication stage. I wonder what can be used to extend abstract class PagerAdapter to extend codebase lifespan.
The javadocs actually has the following deprecation notice on FragmentPagerAdapter:
This class is deprecated.
Switch to ViewPager2 and use FragmentStateAdapter instead.