Android Fragment onPause event called late with FragmentPagerAdapter

1k views Asked by At

I have a FragmentPagerAdapter in an activity that manages 4 fragments, all is working fine, but the onPause, and onDestroyView events of each fragment, are not called immediatly after the new fragment is loaded ie :

FragmentA --> FragmentB --> FragmentC --> FragmentD

the onPause/onDestroyView event of FragmentA is called when I passed to FragmentC, globally these events are called after 2 steps.

Am I missing anything ?

Thanks.

1

There are 1 answers

4
Frank Yin On

FragmentPager will create (effectively keep in memory) 1 off screen page, before and after the currently viewable fragment, this is a feature to keep the pager responsive for swiping. So when a fragment transitions to 2 swipes/pages away then it gets destroyed, hence the delay.

This answer describes how to override this default