FragmentPagerAdapter deprecated FragmentPagerAdapter deprecated android android

FragmentPagerAdapter deprecated


UPDATE 2021-06-14: At this point, ViewPager itself is all but deprecated. Technically, ViewPager is not deprecated, but the two concrete PagerAdapter implementations — FragmentPagerAdapter and FragmentStatePagerAdapter — are deprecated. Ideally, switch to something else, such as ViewPager2 or the pager composable in Accompanist.

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)


The javadocs actually has the following deprecation notice on FragmentPagerAdapter:


This class is deprecated.

Switch to ViewPager2 and use FragmentStateAdapter instead.