Skip to content

Enhance service lifecycle and exit strategy#2039

Merged
jfversluis merged 15 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:FixAndroidDestroyBug
Aug 16, 2024
Merged

Enhance service lifecycle and exit strategy#2039
jfversluis merged 15 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:FixAndroidDestroyBug

Conversation

@ne0rrmatrix
Copy link
Copy Markdown
Member

@ne0rrmatrix ne0rrmatrix commented Jul 19, 2024

  • Fixes bug where closing app from launcher by swiping up to kill app and restarting it no longer resume from where it left off. It start fresh and when u swipe up it exits service and app completely. App will now shutdown completely upon close request from OS.

Description of Change

  • Updated AndroidManifest.xml to improve CommunityToolkit.Maui.Media.Services behavior. Added android:stopWithTask=true and android:foregroundServiceType=mediaPlayback attributes to ensure the service stops with the task and properly manages media playback in the foreground.
  • Added OnDestroy() method in MediaControlsService.android.cs for a more aggressive shutdown approach. This includes logging service destruction, stopping and removing the service from the foreground, finishing and removing the task, exiting the application, and ensuring base class cleanup with base.OnDestroy(). This aims at a cleaner exit and resource management when the service is destroyed.
AndroidDestroyBug.mp4

Linked Issues

PR Checklist

- Updated `AndroidManifest.xml` to improve `CommunityToolkit.Maui.Media.Services` behavior. Added `android:stopWithTask=true` and `android:foregroundServiceType=mediaPlayback` attributes to ensure the service stops with the task and properly manages media playback in the foreground.
- Added `OnDestroy()` method in `MediaControlsService.android.cs` for a more aggressive shutdown approach. This includes logging service destruction, stopping and removing the service from the foreground, finishing and removing the task, exiting the application, and ensuring base class cleanup with `base.OnDestroy()`. This aims at a cleaner exit and resource management when the service is destroyed.
@ne0rrmatrix ne0rrmatrix self-assigned this Aug 4, 2024
@ne0rrmatrix ne0rrmatrix added the 📽️ MediaElement Issue/PR that has to do with MediaElement label Aug 4, 2024
@ne0rrmatrix ne0rrmatrix requested a review from pictos August 8, 2024 07:30
@jfversluis jfversluis enabled auto-merge (squash) August 15, 2024 10:29
@jfversluis jfversluis merged commit 440e4e2 into CommunityToolkit:main Aug 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

📽️ MediaElement Issue/PR that has to do with MediaElement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MediaElement Issue on Android - App Reopens on Last Visited Page and Background Audio Continues

4 participants