3

androidx.fragment.app.FragmentStatePagerAdapter is deprecated and developers are urged to switch to androidx.viewpager2.adapter.FragmentStateAdapter

How can we get the same functionality with FragmentStateAdapter that BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT provided?

This code below is now deprecated

FragmentStatePagerAdapter(
        fragmentManager,
        BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
    )
user1114
  • 1,071
  • 2
  • 15
  • 33

2 Answers2

2

The ViewPager2's FragmentStateAdapter has the same functionality as BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT (this is, in fact, the only type of behavior ViewPager2 supports).

The ViewPager2 migration guide details the exact steps needed to convert to ViewPager2.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
0

The answer is BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT

AndroidX introduces the new FragmentPagerAdapter constructor, please notice its second parameter int behavior.

And in fact, the BEHAVIOR_SET_USER_VISIBLE_HINT is deprecated, so BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT is the only recommended style.

navylover
  • 12,383
  • 5
  • 28
  • 41