'ViewPager2 + FragmentStateAdapter + offscreenPageLimit = 1 => onResume not called
I'm having an issue with my ViewPager, but I don't know why and how to fix it.
So I have a ViewPager2 on which I'm using a FragmentStateAdapter.
This pager contains approx 10 pages (not really important).
On that ViewPager, I also have
viewPager.offscreenPageLimit = 1
From what I understood, when using ViewPager2 + FragmentStateAdapter, onResume should be called on the visible fragment whenever the selected page changes.
However:
- Fragment 1 -> Fragment 2 => onResume/onPause not called
- Fragment 2 -> Fragment 3 => onPause called on Fragment 1 and onResume called on Fragment 3
- Fragment 3 -> Fragment 4 => onPause called on Fragment 3 and onResume called on Fragment 4
- And so on.
So the issue here is onResume is not called on Fragment 2 when I go from Fragment 1 to Fragment 2.
If I remove
viewPager.offscreenPageLimit = 1
Then this fixes the issue. However, I don't understand why... Is it normal? Is it a bug? Am I missing something?
Thank you guys in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
