Android NavigationPage in inconsistent state if Push/Pop operations are performed sometime after app deactivation #16441
Labels
area-navigation
NavigationPage
platform/android 🤖
s/triaged
Issue has been reviewed
s/verified
Verified / Reproducible Issue ready for Engineering Triage
t/bug
Something isn't working
Milestone
Description
On Android, the
NavigationPage
will sometimes fail completely if the app schedules aPushAsync()
orPopAsync()
action sometime after the app has been backgrounded (i.e.Deactivated
andStopped
lifecycle event received from theWindow
).In the case of a scheduled
PopAsync()
, the awaited line sometimes never complete:If the
PopAsync()
task does not complete successfully, the following log message can be observed in LogCat:I am not familiar with Android internals. From what I understand, when the app is backgrounded, the Android system (probably) calls
Activity.onSaveInstanceState()
at some point, which also calls the same method for all its child fragments. This prevented MAUI'sStackNavigationManager
from successfully callingNavigate()
andPopBackState()
... which then means theNavigationFinished
in that class is never called to complete the awaited task.Ultimately, the app's scheduled background push/pop task is in a race against Android's state save calls. In my sample project, you can modify the task delay in
App.xaml:26
to verify this. The shorter the delay, the operation will sometimes succeed. If the delay is longer than 5 seconds, the operation almost always fails.I consider this a bug as the behaviour is not consistent with iOS.
On iOS, when the app is backgrounded, the delayed
PopAsync()
call is not executed until next time the user resumes the app. Eventually the user will observe the correct screen. Same goes forPushAsync()
.Steps to Reproduce
Example PopAsync() Scenario
Deactivated
lifecycle event.Expected
By the time the app is resumed into foreground, user should observe page A
Observed
The user sometimes observe page A, other times observes a white screen instead.
Example PushAsync() Scenario
Deactivated
lifecycle event.Expected
By the time the app is resumed into foreground, user should observe page C
Observed
The user sometimes observe page C, other times observes the original page B. Attempting to pop page B using the UI back button causes the navigation page to show a white view.
Link to public reproduction project repository
https://github.com/Nibby/MAUI-Bug-2
Version with bug
7.0.86
Last version that worked well
Unknown/Other
Affected platforms
Android, I was not able test on other platforms
Affected platform versions
Tested Android API versions 28 and up, and they all exhibited this issue
Did you find any workaround?
The workaround is queue any page transitions requested after an app deactivate / stopped event is received, and execute them after the app is known to be resumed again.
Relevant log output
No response
The text was updated successfully, but these errors were encountered: