Is it safe to assume that adjacent fragments in a ViewPager will always have their UI active?

46 Views Asked by At

I have a ViewPager with FragmentPagerAdapter. I don't override offscreenPageLimit property with setOffscreenPageLimit of my ViewPager. So, in this case the value of the offscreenPageLimit is 1 which is the default value. This means that the app will keep alive both left and right adjacent fragments. Taking above mentioned into account is it safe to assume that onDestroyView is never called on adjacent fragments(until they are adjacent to the currently visible fragment) and access their UI elements although they are not currently visible. Thank you!
P.S.
When I say never I understand that it still might be called when the system will decide to destroy the entire hosting activity. I mean that it will never be called in normal conditions when the user is just interacting with the currently active fragment

1

There are 1 best solutions below

0
A.Jain On

it is completely safe but frgamentPagerStateAdapter will be good to use here instead frgamentPagerAdapter.