diff --git a/samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml b/samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml index e4c429ce3..f592b7eda 100644 --- a/samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml +++ b/samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml @@ -2,7 +2,7 @@ - diff --git a/src/CommunityToolkit.Maui.MediaElement/Services/MediaControlsService.android.cs b/src/CommunityToolkit.Maui.MediaElement/Services/MediaControlsService.android.cs index 629c8bfa7..810c793e2 100644 --- a/src/CommunityToolkit.Maui.MediaElement/Services/MediaControlsService.android.cs +++ b/src/CommunityToolkit.Maui.MediaElement/Services/MediaControlsService.android.cs @@ -217,6 +217,15 @@ void OnSetIntents() notification?.AddAction(actionNext); } + public override void OnDestroy() + { + Platform.CurrentActivity?.StopService(new Intent(Platform.AppContext, typeof(MediaControlsService))); + System.Diagnostics.Trace.TraceInformation("MediaControlsService destroyed."); + Platform.CurrentActivity?.FinishAndRemoveTask(); + System.Environment.Exit(0); + System.Diagnostics.Trace.TraceInformation("Application exiting."); + base.OnDestroy(); + } static void BroadcastUpdate(string receiver, string action) { if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu)