ViewPager and FragmentPagerAdapter: how to notify the fragment instance that it's being switched to another fragment?
<p>I have a <code>ViewPager</code>, <code>FragmentPagerAdapter</code> and a couple fragments. I need to notify the fragment when the user switches to a different one (so that the first one can finalize its work). I'm looking into <code>ViewPager.OnPageChangeListener</code> but can't see any way to get the current fragment instance when the change occurs. Even <code>ViewPager.getCurrentItem()</code> returns the new position when <code>OnPageChangeListener.onPageSelected</code> is called.</p>

<p>Is it guaranteed that <code>Fragment.onPause()</code> will be called for the previous fragment every time when a new one is selected? That would certainly simplify things.</p>