Hello,
You can invoke platform code in MAUI directly. No need to use dependenceService.
I use following code
try
{
if (BackPressCounter == 2)
{
// DependencyService.Get<IAndroidMethods>().CloseApp();
#if ANDROID
Android.OS.Process.KillProcess(Android.OS.Process.MyPid());
#elif IOS
//add your ios platform code to close application
#else
//add your code
#endif
}
else if (Navigation.NavigationStack.Count == 1)
{
BackPressCounter++;
//DependencyService.Get<BackPressMessage>().Show("Double tap to exit");
#if ANDROID
Android.Widget.Toast.MakeText(Android.App.Application.Context, "Double tap to exit", Android.Widget.ToastLength.Long).Show();
#elif IOS
//add your ios platform code to close application
#else
//add your code
#endif
}
else
{
Navigation.PopAsync();
}
}
catch (Exception ex)
{
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.