FragmentStatePagerAdapter is deprecated from API 27

fragmentstatepageradapter vs fragmentpageradapter
fragmentpageradapter kotlin
fragmentstatepageradapter destroyitem
fragmentpageradapter arguments
setuservisiblehint deprecated
fragmentpageradapter disable swipe
fragmentpageradapter replace fragment

FragmentStatePagerAdapter is deprecated from API 27. What's the alternative of FragmentStatePagerAdapter?

private class MainPagerAdapter extends FragmentStatePagerAdapter {

        MainPagerAdapter(FragmentManager fm) {

        public Fragment getItem(int position) {
            Fragment result = new DummyFragment();
             return result;

        public int getCount() {
            return 5;


above code shows FragmentStatePagerAdapter ,getItem and super(fm); as deprecated

The following constructors do the same

super(@NonNull FragmentManager fm)
super(@NonNull FragmentManager fm, BEHAVIOR_SET_USER_VISIBLE_HINT)


The difference in passing those is explained in FragmentPagerAdapter:

 * Indicates that Fragment#setUserVisibleHint(boolean) will be 
 * called when the current fragment changes.
public static final int BEHAVIOR_SET_USER_VISIBLE_HINT = 0;

 * Indicates that only the current fragment will be 
 * in the Lifecycle.State#RESUMED state. All other Fragments 
 * are capped at Lifecycle.State#STARTED.
public static final int BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT = 1;

FragmentPagerAdapter deprecated, Since API 27 FragmentPagerAdapter is deprecated. What's the best alternative to use for this? In my case, I understand something like super(  FragmentStatePagerAdapter is deprecated from API 27. What’s the alternative of FragmentStatePagerAdapter ? private class MainPagerAdapter extends FragmentStatePagerAdapter { MainPagerAdapter ( FragmentManager fm ) { super ( fm ); } @Override public Fragment getItem ( int position ) { Fragment result = new DummyFragment (); return result ; } @Override public int getCount () { return 5 ; } }

You may extend;

and call


in your class's constructor

FragmentPagerAdapter, When using FragmentPagerAdapter the host ViewPager must have a valid ID set. Subclasses only need to This constant is deprecated. This behavior relies on the deprecated Fragment.setUserVisibleHint(boolean) API. FragmentStatePagerAdapter는 API 27에서 deprecated 되었다. 그렇다면 개선하기 위해서는 어떻게 해야할까? was deprecated. 따라서

This works for me.

In Kotlin :

class TasksPagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT )

FragmentStatePagerAdapter, FragmentStatePagerAdapter는 API 27에서 deprecated 되었다. 그렇다면 개선하기 위해서는 어떻게 해야할까? FragmentStatePagerAdapter is deprecated from API 27. FragmentStatePagerAdapter is deprecated from API 27. What's the alternative of FragmentStatePagerAdapter? private

You need to add behavior in your MainPagerAdapter like this:


[Android] FragmentStatePagerAdapter is deprecated from API 27, Would you like to replace it with android . This class was deprecated in API level 27. p> * * @param fm fragment manager that will interact with this adapter  This constructor is deprecated. use FragmentStatePagerAdapter(FragmentManager, int) with BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT. Constructor for FragmentStatePagerAdapter that sets the fragment manager for the adapter. This is the equivalent of calling FragmentStatePagerAdapter(FragmentManager, int) and passing in BEHAVIOR_SET_USER_VISIBLE_HINT.

The constructor with only FragmentManager as a paramaeter is duplicated and changed to

public FragmentStatePagerAdapter(@NonNull FragmentManager fm,
        @Behavior int behavior)

but you can achieve the same by using the below constructor, you should also inject your tabsNumber via constructor to avoid using hard codded numbers, and return it via getCount().

public PagerAdapter(FragmentManager fm, int NumOfTabs) {
    this.numberOfTabs= NumOfTabs;

    public int getCount() {

        return numberOfTabs;

for more details check the official documentation for AndroidX

Fragmentpageradapter is deprecated androidx, This class was deprecated in API level 27. compile "com. May 31, 2013 · This whole Android FragmentPagerAdapter example is made with support library,  Working on android Java, recently updated SDK to API level 29 now there is a warning shown which states that Environment.getExternalStorageDirectory() is deprecated in API level 29 My code is pr

android, FragmentStatePagerAdapter는 API 27에서 더 이상 사용되지 않습니다. @​Deprecated public static final int BEHAVIOR_SET_USER_VISIBLE_HINT = 0;  The C API provides low-level access to the MySQL client/server protocol through the libmysqlclient client library. This is the primary method used to connect to an instance of the MySQL server, and is used both by MySQL command-line clients and many of the MySQL Connectors and third-party APIs detailed here.

Androidx fragmentpageradapter deprecated, But now with API 21 onwards it has been deprecated. here's an example of implementing a FragmentStatePagerAdapter Android class in Kotlin: 27 Dec 2019  This replaces the now deprecated setUserVisibleHint(). FragmentPagerAdapter and FragmentStatePagerAdapter have a new constructor that allows you to switch to the new behavior. (b/129780800) API Changes. moveToState(STARTED) on FragmentScenario can now only be called on API 24+ devices. (b/129880016) Behavior Changes

In general, v4 and v13 are basically the same in most functions, but we can't call them exactly the same thing, after all, there are differences in content. Just as you mentioned that ActivityCompat was deprecated in API level 27.1.0, but it is not the same in Android.Support.V4. We can find this in Hope it can help you.

  • I have the same problem. I had switched from v4 to v13, so that I could use standard fragments in the code (not the support fragments and the support fragment manager). Now it looks like I need to switch back to support fragments. At least half a day editing of code :-(
  • Refactored the code for Androidx support libraries, hopefully it remains stable for some time now.
  • If you use AndroidX, you may do it in such a way…
  • Have a look:
  • Does this affect the functionality in any way?
  • But it is deprecated. What to use alternatively to FragmentStatePagerAdapter?
  • Could you please check your imports: are you using or
  • You are right, it was the incorrect import. This does work.
  • Added this and a button in one of my fragments stopped responding to its onClick function
  • I use your code but i got lint error "must be one of BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT)" what should i do?
  • FragmentStatePagerAdapter is deprecated also
  • I think that despite having had the wrong links (which I just fixed), this answer is correct: v4 FragmentStatePagerAdapter is not deprecated.… @Ernesto I'm not sure which version of FragmentStatePagerAdapter your comment refers to.