Fixed
Status Update
Comments
jg...@google.com <jg...@google.com> #2
Can you please double check the link to your git repository for the repro? It leads to a 404
jg...@google.com <jg...@google.com> #3
sa...@gmail.com <sa...@gmail.com> #4
After looking at the code, what surprises me is that it works on Android 12.
The correct way to achieve this is to never return false in the KeepOnScreenCondition
. Otherwise, the time between the condition being false and the new activity being visible will let the splash screen activity appear
The condition is evaluated for the current view tree only, so as soon as you start the next activity, it will be ignored and the splash screen will be removed.
jg...@google.com <jg...@google.com> #5
I'm marking this as working as intended, but please let me know if it doesn't work.
jg...@google.com <jg...@google.com> #6
This was raised on GitHub as well: https://github.com/googlesamples/android-viewpager2/issues/3#issue-434618886
Copying the content here as closing GitHub issue tracker (want to have one place to track things).
AndyGu commented 5 hours ago
The scenes I met is that when I store fragments in viewpager2, then I switch them using ”setCurrentItem(position, false)“, there is no certain method called in Fragment's lifecycle, sometimes it calls onAttach() onCreate() and so on, sometimes no method is called(it is related to the memory management I guess). I know I can call registerOnPageChangeCallback of viewpager2, but what I faced is I may fail when I do something to the fragment that I setCurrentItem to, because the fragment will init again when the lifecycle methods called after the callback of onPageSelected.
So am I do the code wrong way or is there some certain method can be called in fragment when switching the fragments, or I can call some method to manage the memory of viewpager2?
Copying the content here as closing GitHub issue tracker (want to have one place to track things).
AndyGu commented 5 hours ago
The scenes I met is that when I store fragments in viewpager2, then I switch them using ”setCurrentItem(position, false)“, there is no certain method called in Fragment's lifecycle, sometimes it calls onAttach() onCreate() and so on, sometimes no method is called(it is related to the memory management I guess). I know I can call registerOnPageChangeCallback of viewpager2, but what I faced is I may fail when I do something to the fragment that I setCurrentItem to, because the fragment will init again when the lifecycle methods called after the callback of onPageSelected.
So am I do the code wrong way or is there some certain method can be called in fragment when switching the fragments, or I can call some method to manage the memory of viewpager2?
jg...@google.com <jg...@google.com> #8
It's definitely on our radar - we'll be looking into it soon.
Description
Instead, I propose using existing fragment lifecycle methods. Off-screen fragments would be paused while the current page's fragment would be resumed. This would allow you to implement logic in the same way for fragments in a ViewPager as anywhere else in the application.