question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing the root page when navigating crashes the application on Android

See original GitHub issue

Description

Hello friends,

First, I would like to THANK YOU all for #dotnetmaui, being honest, it has been a delight developing apps using .NET MAUI. It is fast, reliable and overcool! Developing UI using Borders is probably my favorite feature ever in the world! It is so much easy now to style form controls or any other element in the UI with Borders, it is just amazing.

Let me start detailing the issue, I’m facing.

Note: I’m using Prism.Maui on the application, I know it is still on beta, however, I believe this issue is related to MAUI and not Prism itself.

The application has defined a flow for non-logged users and logged users. Any flow starts with the OnBoarding page, this page provides just a welcome message to the users and it is in charge of redirect the logged users to the Dashboard page. However, if the user is at the OnBoarding screen, and for example (just for the demo) I click on Sign In button and want to redirect the user to the Dashboard screen and for instance remove from the navigation stack the root page and now Dashboard become the root page, so we prevent logged the users to navigate back while the app is open.

So, when navigating to a page we change the root and on Android it appears to do a jump into another app somehow and for instance it generates an issue. I’m sharing a video to demo it below:

https://user-images.githubusercontent.com/1047398/197197951-df6299de-d96e-4e7c-a109-12cd80791703.mp4

image

Steps to Reproduce

  1. Create a new Maui Application
  2. Add Prism.Maui to the project and setup the initialization
  3. Create a 2 Views and 2 ViewModels
  4. Register them on Prism.Maui
  5. Navigate from one page to another page (Not modal)

Link to public reproduction project repository

https://github.com/vhugogarcia/acceso/tree/feature/base-architecture

Version with bug

7.0 Release Candidate 2

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android (any version)

Did you find any workaround?

I could not find a workaround at this moment.

Relevant log output


The code I'm using to navigate to another page is:
 _navigationService.NavigateAsync(uri)
            .OnNavigationError(ex => Debug.WriteLine(ex));

I believe this is the source code from Prism.Maui: https://github.com/PrismLibrary/Prism.Maui/blob/master/src/Prism.Maui/Navigation/PageNavigationService.cs

Error Message: Either set MainPage or override CreateWindow.
Error Source: Microsoft.Maui.Controls
Error StackTrace:
   at Microsoft.Maui.Controls.Application.CreateWindow(IActivationState activationState) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Application\Application.Impl.cs:line 126
   at Microsoft.Maui.Controls.Application.Microsoft.Maui.IApplication.CreateWindow(IActivationState activationState) in D:\a\_work\1\s\src\Controls\src\Core\HandlerImpl\Application\Application.Impl.cs:line 40
   at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity activity, IApplication application, Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\ApplicationExtensions.cs:line 44
   at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle savedInstanceState) in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.cs:line 32
   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.App.Activity.cs:line 2816
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 121

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
PureWeencommented, Oct 31, 2022

@vhugogarcia yea, so you can just hide or show Shell parts to do that or just create different areas

<Shell>
<ShellContent Route="LoginFlow" IsVisible={Binding IsAnonymous} />
<FlyoutItem IsVisible={Binding IsLoggedIn} ></Flyout>

Or just

<Shell>
<ShellContent Route="LoginFlow" IsVisible={Binding IsAnonymous} />
<FlyoutItem/TabBar IsVisible={Binding IsLoggedIn} Route="LoggedIn":></Flyout>

Then when they log in

Shell.Current.GotoAsync("//LoggedIn")

Some variation of above

1reaction
gerry123commented, Nov 17, 2022

I can confirm that #10271 is fixed in VS 17.4.1 (.net 7.0.100)…

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Quickly changing Bottom Navigation app crashes
The problem is my app crashes if i start clicking randomly and change fragment quickly, when i check logcat it shows NPE while...
Read more >
Crashes | App quality
An Android app crashes whenever there's an unexpected exit caused by an unhandled exception or signal. An app that is written using Java...
Read more >
Tasks and the back stack
If no task exists for the app, then a new task is created and the main activity for that app opens as the...
Read more >
Managing WebView objects
This page describes how to use these APIs to work with WebView objects more effectively, improving your app's stability and security.
Read more >
How to fix Maps when it crashes - Android
On your Android phone or tablet, open the Settings app . Tap Apps & notifications. Follow the steps on your device to find...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found