I'm aware that my question is a little bit general, but is there any way to prevent app from being closed in Windows and Android as well? I've noticed that there is no longer available to override the OnClosing method and setting Cancel to true in Window class like it was in WPF and that's propably because MAUI is supposed to be multiplatform environment.
So is there maybe some way to put app in/as a service or some other way to put it in a background and prompt some notification when all calculations are done?
As far as I get was to override OnDestroying in Window class but I've got no idea what to do next.
In App.xaml.cs:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new AppShell();
}
protected override MyWindow CreateWindow(IActivationState activationState)
{
return new MyWindow(MainPage);
}
}
In MyWindow.cs:
public class MyWindow : Window
{
public MyWindow() : base()
{
}
public MyWindow(Page page) : base(page)
{
}
protected override void OnDestroying()
{
System.Diagnostics.Debug.WriteLine("Destroying");
}
protected override void OnStopped()
{
System.Diagnostics.Debug.WriteLine("Stopping");
}
protected override void OnDeactivated()
{
System.Diagnostics.Debug.WriteLine("Deactivating");
}
I've also noticed that OnStopped was fired before OnDestroying which really made me confused, beacuse it is not acting like it is described in MAUI documentation.
Output:
Destroying
Stopping
Deactivating
The program '[9736] MauiApp.exe' has exited with code 0 (0x0).