Search code examples
androidandroid-fragmentsandroid-viewpagerfragmentmanager

What causes a fragment created by a FragmentPagerAdapter to still be known to FragmentManager after the adapter calls onDestroy?


I have a standard FragmentPagerAdapter subclass that implements getItem and getCount. The adapter has 3 items, so when the third is reached, the fragment for the first item should be destroyed.

I have verified that destroyItem is called for position 0. But when I return to page 1, inside instantiateItem of FragmentPagerAdapter, mFragmentManager.findFragmentByTag(name); is not null. Causing it to reattach the fragment.

How can I change it so when destroyItem is called, it will not find the same fragment in instantiateItem? I would prefer a new fragment to be created.


Solution

  • I found out that's why it's FragmentPagerAdapter and not FragmentStatePagerAdapter.

    Duh!