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.
Technically, ViewPager is not deprecated, but the two concrete PagerAdapter implementations — FragmentPagerAdapter and FragmentStatePagerAdapter — are deprecated.
You can use startActivityForResult(or broadcast/receiver) to get the result from the activity. Then use adapter. notifyDataSetChanged to refresh the fragment.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With