Error when navigating back and using a NavigationPage
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 296
Description
### Description
When using a navigation page, then navigating forward
`await navigationPage.Navigation.PushAsync(new NewPage1());`
And then navigating back by either pressing the back button or by
`await navigationPage.Navigation.PopAsync();`
The following error is thrown only on Android on Windows it works correctly.
Also, even though the error is thrown on Android, it doesn't crash the application, the navigation works as expected but the following error message is shown in the output.
```
Unhandled Exception: Java.Lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
--- End of managed Java.Lang.IllegalArgumentException stack trace ---
java.lang.IllegalArgumentException: No destination with ID 3 is on the NavController's back stack. The current destination is Destination(0x2) class=crc6452ffdc5b34af3a0f.NavigationViewFragment
at androidx.navigation.internal.NavControllerImpl.getBackStackEntry$navigation_runtime_release(NavControllerImpl.kt:1709)
at androidx.navigation.NavController.getBackStackEntry(NavController.android.kt:1128)
at crc64fcf28c0e24b4cc31.ButtonHandler_ButtonClickListener.n_onClick(Native Method)
at crc64fcf28c0e24b4cc31.ButtonHandler_ButtonClickListener.onClick(ButtonHandler_ButtonClickListener.java:29)
at android.view.View.performClick(View.java:8083)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1218)
at android.view.View.performClickInternal(View.java:8060)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:31549)
at android.os.Handler.handleCallback(Handler.java:995)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loopOnce(Looper.java:248)
at android.os.Looper.loop(Looper.java:338)
at android.app.ActivityThread.main(ActivityThread.java:9067)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932)
```
I've attached a sample application to reproduce the problem.
### Steps to Reproduce
1. Create a MAUI project
2. Add a Navigation page
3. Navigate to a page
4. Navigate to another page
5. Navigate backwords (the error is thrown)
### Link to public reproduction project repository
https://github.com/RaulBastian/maui-navigation-error
### Version with bug
10.0.20
### 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 and Android 16, unknown if it happens on other versions
### Did you find any workaround?
No work around for now
### Relevant log output
```shell
```
Contributor guide
Research direction
Start with the linked maui-navigation-error reproduction and run its NavigationPage flow on Android. Exercise PushAsync followed by the system back button or PopAsync, then trace the Android navigation path associated with the NavController back-stack error. Done means the sample can navigate back without emitting the reported exception while preserving the working behavior on other platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100