Open mnxamdev opened 4 years ago
I've got the feeling that currently windows rarely suspends uwp applications so maybe the events didn't fire because they didn't actually happen.
edit: or perhaps I've just been seeing this bug for so long that I've assumed it is the normal behaviour...
It looks like the Xamarin.Forms code should be reacting to the EnteredBackground and LeavingBackground events rather than Suspending and Resuming events, from version 1607 of Windows 10
As a quick experiment, I added to my App.xaml.cs:
EnteredBackground += (s, e) => { Application.Current?.SendSleep(); };
LeavingBackground += (s, e) => { Application.Current?.SendResume(); };
It looks like the Xamarin.Forms code should be reacting to the EnteredBackground and LeavingBackground events rather than Suspending and Resuming events, from version 1607 of Windows 10
Thanks for the suggestion. I just tried that and I'm not seeing that event handler get hit either. Will add it to my report. However, I'm not able to find that SendResume() method.
Worst thing about troubleshooting this "resume" issue and searching online is you get a lot of tech resumes. 😆
I haven't checked, but it might be that you need to target a newer Windows build. I am targeting 18362. If that is the case, it might require a check of UniversalApiContract level before deciding what to do.
@johnshardman It looks like that event only fires when I minimize the app and not just switch to a different app when it's not minimized. That seems inline with the documentation mentioned above regarding App Suspend. However, there seems to be a lifecycle event not being handled here:
Running in the foreground Running in the foreground means that your app's UI is visible.
The LeavingBackground event is fired just before your application UI is visible and before entering the running in foreground state. It also fires when the user switches back to your app.
We are targeting 18362 as well:
We recently took on updating Prism and Unity and tried updating to Prism.Unity.Forms 7.2.0 and updating to Unity 5.11.7 but that didn't seem to alleviate the issue. I've updated the report above with this info.
Lifecycle events do not fire on UWP.
Steps to Reproduce
Note, we also tried updating to Prism.Unity.Forms 7.2.0 and updating to Unity 5.11.7 but that didn't seem to alleviate the issue.
This is not related as I'm not attached to the debugger, sending events from the debugger works: https://xamarin.github.io/bugzilla-archives/46/46526/bug.html
Note the following Microsoft documentation: https://docs.microsoft.com/en-gb/windows/uwp/launch-resume/app-lifecycle?redirectedfrom=MSDN#app-suspend
https://docs.microsoft.com/en-gb/windows/uwp/launch-resume/app-lifecycle?redirectedfrom=MSDN#running-in-the-background
Expected Behavior
Code in OnSleep or OnResume should run.
Actual Behavior
Code in OnSleep or OnResume doesn't run.
Basic Information
Workaround
Tried wiring up the following and this didn't work either:
Application.Current.Suspending += Current_Suspending;
Application.Current.Resuming += Current_Resuming;
Application.Current.LeavingBackground += Current_LeavingBackground;