FragmentPagerAdapter deprecated

后端 未结 3 1350
北恋
北恋 2020-12-28 11:43

Since API 27 FragmentPagerAdapter is deprecated. What\'s the best alternative to use for this?

In my case, I understand something like super(fragm

相关标签:
3条回答
  • 2020-12-28 12:21

    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)

    0 讨论(0)
  • 2020-12-28 12:22

    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.

    0 讨论(0)
  • 2020-12-28 12:25

    The javadocs actually has the following deprecation notice on FragmentPagerAdapter:


    This class is deprecated.

    Switch to ViewPager2 and use FragmentStateAdapter instead.


    0 讨论(0)
提交回复
热议问题