In my .NET Maui hybrid application using Blazor, I have a requirement: when a user attempts to navigate back or presses the back button in the mobile app, I need to display a confirmation popup asking if they want to close the application before proceeding to close the app. I tried below code in App.xaml.cs, but its showing pop up when opening the application again. I want to know which method to be called just before closing the application.
public partial class App : Application
{
private IAudioPlayer _audioPlayer;
private IAudioManager _audioManager;
private NavigationManager NavigationManager;
public bool isPlaying = true;
public App(IAudioManager audioManager)
{
InitializeComponent();
MainPage = new MainPage();
_audioManager = audioManager;
}
protected override Window CreateWindow(IActivationState? activationState)
{
Window window = base.CreateWindow(activationState);
window.Created += (s, e) =>
{
// Custom logic
};
window.Destroying += (s, e) =>
{
_audioPlayer.Stop();
};
window.Deactivated += (s, e) =>
{
if (_audioPlayer != null)
{
_audioPlayer.Stop();
}
};
window.Deactivated += Window_Deactivated;
return window;
}
}
I tried to do something like this in App.xaml.cs but with after closing the app it calling so that opening again my pop is showing.