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

navHost cannot be null after app2app #15788

Closed
tkern46 opened this issue Jun 22, 2023 · 8 comments
Closed

navHost cannot be null after app2app #15788

tkern46 opened this issue Jun 22, 2023 · 8 comments
Labels
area-navigation NavigationPage platform/android 🤖 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@tkern46
Copy link

tkern46 commented Jun 22, 2023

Description

I noticed an InvalidOperationException (NavHost cannot be null) after app-to-app-communication via intents.
To reproduce this bug I have created 2 App (LoginApp and CallingApp). The LoginApp called via intent out of CallingApp. To simulate the login-process, the LoginApp waits for 2 seconds and finishes the intent. When the intent is finished and you go back into the LoginApp, the LoginApp crashes because the navHost is null.
It did not crash using Xamarin with dotnet 2.1.

Steps to Reproduce

  1. Start LoginApp
  2. Start CallingApp
  3. Wait until LoginView disappears and "Hello from CallingApp!" is displayed
  4. Open still running LoginApp => InvaldiOperationException pops up

Link to public reproduction project repository

https://github.com/tkern46/navhost-connot-be-null-after-app2app.git

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android API 29

Did you find any workaround?

No response

Relevant log output

[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: NavHost cannot be null
[mono-rt] at Microsoft.Maui.Platform.StackNavigationManager.get_NavHost() in D:\a_work\1\s\src\Core\src\Platform\Android\Navigation\StackNavigationManager.cs:line 32
[mono-rt] at Microsoft.Maui.Platform.NavigationViewFragment.OnResume() in D:\a_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationViewFragment.cs:line 75
[mono-rt] at AndroidX.Fragment.App.Fragment.n_OnResume(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:line 2614
[mono-rt] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22
[mono-rt] at Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod(JniObjectReference instance, JniObjectReference type, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 12320
[mono-rt] at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 75
[mono-rt] at Android.App.Activity.OnPostResume() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.App.Activity.cs:line 4296
[mono-rt] at Microsoft.Maui.MauiAppCompatActivity.OnPostResume() in D:\a_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.Lifecycle.cs:line 66
[mono-rt] at Android.App.Activity.n_OnPostResume(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.App.Activity.cs:line 4286
[mono-rt] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22
@tkern46 tkern46 added the t/bug Something isn't working label Jun 22, 2023
@Eilon Eilon added the area-navigation NavigationPage label Jun 22, 2023
@mattleibow mattleibow added this to the Backlog milestone Jun 22, 2023
@ghost
Copy link

ghost commented Jun 22, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@mattleibow
Copy link
Member

@PureWeen thoughts?

@PureWeen PureWeen added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jun 22, 2023
@ghost
Copy link

ghost commented Jun 22, 2023

Hi @tkern46. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@tkern46
Copy link
Author

tkern46 commented Jun 23, 2023

Hi, the exception still occures with the latest releases. We've tried it with Visual Studio Preview 17.7.0 Preview 2.0 and the .net8 preview.

@ghost ghost removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jun 23, 2023
@markusroessler
Copy link

note this exception doesn't occur, if you create a custom Window in App.xaml.cs.CreateWindow() and set the MainPage in this Window instead of the App.
However this leads to a memory leak instead: #15972

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jan 2, 2024
@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio Enterprise 17.9.0 Preview 2. Can repro on android platform with sample project.
navhost.zip
image

@PureWeen PureWeen added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label May 3, 2024
@PureWeen
Copy link
Member

PureWeen commented May 3, 2024

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

My thinking is that you'll need to set the launchmode on your android activity to "SingleTop" in order to fix your exception. We've added an additional exception message as well in case that's what you're hitting.

Copy link
Contributor

Hi @tkern46. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dotnet-policy-service dotnet-policy-service bot removed this from the Backlog milestone May 11, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-navigation NavigationPage platform/android 🤖 s/triaged Issue has been reviewed s/try-latest-version Please try to reproduce the potential issue on the latest public version s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants