Search code examples
androidandroid-activityandroid-fragmentsandroid-tabspagerslidingtabstrip

Strange issue with Material PagerSlidingTabStrip, FragmentPagerAdapter, and BackStack management


I am creating Scrollable Tabs per the Material Design guidelines, but I run into a strange issue when I switched from a PagerAdapter to a FragmentPagerAdapter. This issue only occurs after I have navigated to my tab fragment, hit back, then navigated to it again.

A screen recording of the issue is visible at this URL.

I am using this library: jpardogo/PagerSlidingTabStrip for my fragments. This is the code on how I am instantiating this fragment.

@OnItemClick(R.id.home_list_listview)
     void onItemSelected(int position) {
         getActivity().getSupportFragmentManager().beginTransaction()
                 .replace(R.id.container, new SlidingFragment())
                 .addToBackStack(null)
                 .commit();
     }

Am I missing something basic in the fragment lifecycle here? SlidingFragment is just a blank fragment, so it doesn't need to be constructed in a special way. I'm trying to pinpoint whether it's a bug in the library or my own code.


Solution

  • Turns out I was having some issues with OnDestroyItem(). I switched to a FragmentStatePagerAdapter and everything works great now