Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'FragmentStatePagerAdapter(androidx.fragment.app.FragmentManager)' is deprecated

Tags:

Recently the androidx.fragment.app.FragmentManager is deprecated and no proper solutions are available.

Have tried to implement support V4 but did not work with AndroidX. It shows library not found.

PagerAdapter:

public ViewPagerAdapter(FragmentManager manager) {     super(manager);     //... } 

Thanks in advance.

like image 500
Saswata Avatar asked May 19 '19 13:05

Saswata


People also ask

Is Viewpager deprecated?

Technically, ViewPager is not deprecated, but the two concrete PagerAdapter implementations — FragmentPagerAdapter and FragmentStatePagerAdapter — are deprecated.

How do I refresh FragmentStatePagerAdapter?

You can use startActivityForResult(or broadcast/receiver) to get the result from the activity. Then use adapter. notifyDataSetChanged to refresh the fragment.

What is Fragment page adapter?

Implementation of PagerAdapter that represents each page as a Fragment that is persistently kept in the fragment manager as long as the user can return to the page. This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs.

What is the difference between FragmentPagerAdapter vs FragmentStatePagerAdapter?

FragmentPagerAdapter is used exactly like FragmentStatePagerAdapter . It only differs in how it unloads your fragments when they are no longer needed (Figure 11.4). With FragmentStatePagerAdapter , your unneeded fragment is destroyed.


1 Answers

Recently the androidx.fragment.app.FragmentManager is deprecated

It is not deprecated at the present time. For example, it is not marked as deprecated in the documentation.

'FragmentStatePagerAdapter(androidx.fragment.app.FragmentManager)' is deprecated

The single-parameter FragmentStatePagerAdapter constructor is deprecated. However, if you read the documentation for that constructor, you will find:

This constructor is deprecated. use FragmentStatePagerAdapter(FragmentManager, int) with BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT

So, replace FragmentStatePagerAdapter(fm) with FragmentStatePagerAdapter(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT), to retain the functionality from the original one-parameter constructor.

like image 140
CommonsWare Avatar answered Sep 25 '22 04:09

CommonsWare