Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Attachment actions
Description
Version used: 1.0.0-alpha1, using SDK 27/28
Devices/Android versions reproduced on: Emulators from API 21 to 26
When a Fragment is set as a "pop" destination for a action, it is "resumed" even though it is not shown on the screen.
I attached a sample projet to show the problem.
Here is the setup:
Very simple MainActivity, with one NavHostFragment and 3 Fragments: FragmentOne, FragmentTwo, FragmentThree.
The nav graph is simple:
* FragmentOne can go to FragmentTwo
* FragmentTwo can go to FragmentThree
* The "pop" destination of the action is FragmentOne
FragmentOne contains a Log.v() in its onResume() method.
How to reproduce:
* Start the app
* In Logcat, see "onResume", as the FragmentOne is shown
* Navigate to FragmentTwo
* Navigate to FragmentThree
* In Logcat, see "onResume", as the FragmentOne is resumed for some reason => BUG ?
* Press back
* In Logcat, see "onResume", as the FragmentOne is shown
As you see, the FragmentOne is shown only twice on screen, but Logcat shows "onResume" three times.
Now as a counter example:
* Open the Nav Graph and remove the "pop" destination (line 24, app:popUpTo="@+id/fragmentOne")
* Start the app
* In Logcat, see "onResume", as the FragmentOne is shown
* Navigate to FragmentTwo
* Navigate to FragmentThree
* In Logcat, you don't see anything
* Press back
* FragmentTwo is shown, nothing in Logcat
* Press back
* In Logcat, see "onResume", as the FragmentOne is shown
=> FragmentOne is shown twice, Logcat shows "onResume" twice.
To me it's clearly a bug as the whole lifecycle of FragmentOne is triggered even though the Fragment is never shown on screen.
It cause me a problem: I wanted to refresh my view (doing an HTTP fetch) when the Fragment is resumed. Because of this bug, the fragment fetches from the network even though it is never shown.
I tried to play with isVisible()
(
Any thoughts about this? Thanks!