Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] When device locked/using another app, if Navigation occurs it will fail and leave the app in a broken state #21113

Closed
BurkusCat opened this issue Mar 9, 2024 · 6 comments
Labels
area-navigation NavigationPage platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@BurkusCat
Copy link
Contributor

BurkusCat commented Mar 9, 2024

Description

When doing navigation, it isn't always happening immediately after a user's button press. Sometimes an app may need to do some processing or sometimes the page switch may be on a timer (for example, you may only want allow a user access to a screen for 1 minute before removing them from that page).

If the user decides to lock their Android phone or switch to another app, the app can get into a broken state if the navigation happens during this period. In the console when debugging, I can see this:
[FragmentNavigator] Ignoring navigate() call: FragmentManager has already saved its state which presumably means Android is trying to save a state for the app which is causing problems with MAUI's navigation attempt.

With Java Exceptions ticked in Exception Settings, you will hit this error on any navigation related lines:

Java.Lang.IllegalArgumentException: 'No destination with ID 2 is on the NavController's back stack. The current destination is Destination(0x1) class=crc6452ffdc5b34af3a0f.NavigationViewFragment'

In the below video, I first demonstrate the navigation if you stay in the app at all times. I then demonstrate pressing the button, locking the device, and returning to find the app in a broken state. The user must restart the app to get things back to normal again.

lockscreen-repro.mp4

Steps to Reproduce

  1. Have navigations scheduled to happen on a timer or have some processing occur before a navigation (essentially a delay of some sort)
  2. Lock your Android device or switch to using another app
  3. The navigation code executes

Expected
The app performs the navigation and when you resume the app, it is on the new page as expected

Actual
The app tries to perform the navigation but it conflicts with Android state saving. This can leave the app in a broken state. A few examples of what I've seen:

  • Blank screen
    image

  • The new page's navigation bar over the top of the original page

  • The original page with a back button when it shouldn't have one

I have to imagine this will cause difficult to reproduce issues for many apps. I think any app that does something like an API call on a button press where after the API call, a page is pushed or popped, the app will get into an unrecoverable state.

Link to public reproduction project repository

https://github.com/BurkusCat/NavigationWhenLockedMauiRepro

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14. I'm assuming other versions too

Did you find any workaround?

No workaround found. I tried using Dispatcher/BeginInvokeOnMainThread/ConfigureAwait(false) and I tried different Android LaunchMode's. I couldn't find anything that resolved the issue.

Relevant log output

No response

@BurkusCat BurkusCat added the t/bug Something isn't working label Mar 9, 2024
@BurkusCat
Copy link
Contributor Author

I was thinking that it is probably possible to reproduce this bug in other MAUI apps, not just mine. So I decided to download a very popular (1mil+ downloads) .NET MAUI app and see if I could do it. As you can see, I was able to reproduce this same issue just on the sign in page where it gets stuck & needs restarted:
image

I expect that it would be possible to reproduce this issue in many MAUI apps and its one where users sometimes encounter it & it breaks the app, but they aren't able to provide good enough reproduction steps for why it happened.

@PureWeen
Copy link
Member

Can you test with the latest nightly build?
https://github.com/dotnet/maui/wiki/Nightly-Builds

@PureWeen PureWeen added platform/android 🤖 area-navigation NavigationPage s/needs-info Issue needs more info from the author labels Mar 11, 2024
@BurkusCat
Copy link
Contributor Author

I've updated my sample to use 8.0.20-nightly.10298 and it appears to work well! 🎉

I was curious and found that 8.0.10-nightly.10196 was the first one with the fix. I think it was this PR that resolved the issue: #19532

@markusroessler
Copy link

@PureWeen Is this issue supposed to be fixed in 8.0.10? I can still reproduce this using a NavigationPage and navigating while the app is in background. The console message Ignoring navigate() call is not appearing anymore though.

@markusroessler
Copy link

markusroessler commented Mar 22, 2024

@PureWeen The issue still occurs when the initial navigation is done while the app is in background (use new NavigationPage() instead of new NavigationPage(new MainPage()) ). Tested with 8.0.20-nightly.10336. Can we reopen this or should I file a new issue?

sample app:
https://github.com/markusroessler/MauiBackgroundNavigation/tree/main/MauiBackgroundNavigation

@PureWeen
Copy link
Member

PureWeen commented Mar 22, 2024

@PureWeen The issue still occurs when the initial navigation is done while the app is in background (use new NavigationPage() instead of new NavigationPage(new MainPage()) ). Tested with 8.0.20-nightly.10336. Can we reopen this or should I file a new issue?

sample app: https://github.com/markusroessler/MauiBackgroundNavigation/tree/main/MauiBackgroundNavigation

Can you log a new issue please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-navigation NavigationPage platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants