dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

PushAsync hangs if app is running in the background #25009

Open jimbr32 opened 1 week ago

jimbr32 commented 1 week ago

Description

If PushAsync is called to push a view onto the navigation stack while the app is in the background, the call hangs until the app returns to the foreground. Video 9-30 at 9.55.webm

Steps to Reproduce

Call PushAsync to push a view onto the stack while the application is in the background. I am using this code to duplicate:

private async void OnTestPageClicked(object sender, EventArgs e) { Console.WriteLine("Starting 5 second delay"); await Task.Delay(5000); Console.WriteLine("Before PushAsync for TestPage"); await Navigation.PushAsync(new TestPage()); Console.WriteLine("After PushAsync for TestPage"); }

See https://github.com/jimbr32/maui-samples/blob/4f2715431eafa43950890838a5eeea4df5ef6d67/MauiApp3/MauiApp3/MainPage.xaml.cs#L12

Link to public reproduction project repository

https://github.com/jimbr32/maui-samples

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

Android 11 and up, iOS 16.6

Did you find any workaround?

No response

Relevant log output

No response

jfversluis commented 1 week ago

You selected the option that specifies that this worked in Xamarin.Forms? Are you certain that is the case?

Also what would be the use case for this? Is it something you can capture with the app/page lifecycle events? I don't think there is any guarantee on all the platforms that code will run when your app goes to the background.

jimbr32 commented 1 week ago

You selected the option that specifies that this worked in Xamarin.Forms? Are you certain that is the case?

Also what would be the use case for this? Is it something you can capture with the app/page lifecycle events? I don't think there is any guarantee on all the platforms that code will run when your app goes to the background.

Sorry I didn't clarify ... I am certain this worked with Xamarin forms for Android. It never worked on iOS as far as I know. Android is our primary platform. If this only worked on Android for now it would definitely help us.

As for the use case, our app starts an Android foreground service which allows our app to run in the background. While in the background the app navigates forms by reacting to external events like network transactions, speech input, and so on. If the user brings the app to the foreground they need to be able to see the current view, and possibly use the back button to navigate back.

ninachen03 commented 1 day ago

This issue has been verified using Visual Studio 17.12.0 Preview 2.1(8.0.91 & 8.0.10) can repro on android platform. But on (8.0.7 - 8.0.3) their behavior is different from what users describe, after the app is running in the background then return to the foreground cannot navigate to new page.