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

While working with Viewpager with FragmentPagerAdapter i have noticed this deprecated messages. i have created FragmentPagerAdapter class like below 

class MyViewPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager)



To overcome the issue i have modified FragmentPagerAdapter() constructor

Solution 1: By replacing the above code with below code we can resolve the error

class MyViewPagerAdapter(manager:FragmentManager) : FragmentPagerAdapter(manager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)


Solution 2:

AndrodViewpager 2

There is another way to fix the issues by "Migrate from ViewPager to ViewPager2"

By switch from Viewpager to ViewPager2 and create adapter by FragmentStateAdapter or FragmentStatePagerAdapter instead