Fix: Resolve ForegroundServiceStartNotAllowedException in MusicService#1198
Merged
theovilardo merged 1 commit intotheovilardo:masterfrom Feb 22, 2026
Merged
Conversation
5969e9e to
b428aeb
Compare
b428aeb to
a1cc496
Compare
This was referenced Feb 24, 2026
Closed
Closed
Closed
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This PR addresses the
android.app.ForegroundServiceStartNotAllowedExceptioncrash affecting users on Android 12+ (API 31+), as reported in the recent crash log.Background
The crash occurs because Android 12+ restricts starting foreground services from the background. In our Media3 implementation, when the

MediaNotificationManagerasynchronously updates the notification (e.g., afterCoilBitmapLoaderfinishes fetching album art), the app might have already lost its foreground status or playback focus, causing the system to reject the request to start the service in the foreground.Problem (Reason for Fix)
The app currently crashes on Android 12+ devices when updating the media notification in certain background states.
Stack Trace:
Click to view full Exception
Changes
onUpdateNotificationinMusicServiceto perform proactive checks.playWhenReady == true) and is not in anIDLEstate. If these conditions aren't met, the notification is downgraded to a standard background notification, preventing the crash.try-catchblocks (includingThrowablefor critical system interrupts) around the notification update pipeline to ensure app stability even if Media3's internal state becomes inconsistent.Impact
This fix prevents immediate app closure when the media notification is refreshed while the app is in the background, significantly improving reliability on modern Android devices.
Testing