-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service doesn't get stopped after setting idle
state with androidStopForegroundOnPause
disabled
#1083
Comments
That's the correct behaviour. If you want to instruct Android to call |
Yeah, that makes sense, but the problem I'm facing - no way to get rid of that notification by setting the state to idle. |
So, I want to clarify a bit: I'm not asking "why doesn't service stop when player is paused", but rather "why doesn't service stop when player is in idle state". After digging a bit, I found this issue: #996. This comment explains the exact same issue I have. |
I'm facing a similar issue @Zensonaton. I feel like as things currently stand, there are two options:
I also agree that the battery optimization option isn't great, but I also understand that we're kinda fighting against flaws in the OS at this point. |
Is it possible to integrate a "destroyNotification" function to manually dismiss the notification? |
I'm using the default AudioServiceConfig but still the notification behavior is inconsistent after stopping the audio and calling the stop method of BaseAudioHandler. let's say 5 out of 10 times the notification gets dismissed while the rest of times it stays there.
|
I made a few modifications that I think better aligns with the current AudioProcessingState: https://github.com/Colton127/audio_service AudioProcessingState.idle: Stop foreground service and remove notification. AudioProcessingState.completed: Stop foreground service, but keep notification active, allowing users to restart playback at a later time through the notification. On my branch, AudioProcessingState.idle always kills the notification on Android 14, but I don't think it's possible on Android 11. I believe the lifecycle of the service should mirror that of Spotify and YouTube: The service remains active until the notification or app is swiped away by the user. Previously, this wasn't necessary, but now that we cannot momentarily pause and resume the service in the background, we need to keep it alive. |
Documented behaviour
AudioServiceConfig.androidStopForegroundOnPause
: Whether the Android service should switch to a lower priority state when playback is paused allowing the user to swipe away the notification. Note that while in this lower priority state, the operating system will also be able to kill your service at any time to reclaim resources.BaseAudioHandler.stop
: Stop playback and release resources. The default implementation (which may be overridden) updates playbackState by setting the processing state to AudioProcessingState.idle which disables the system notification.Actual behaviour
Changing
androidStopForegroundOnPause
from true (default) to false no longer allows stopping foreground service (and notification) by settingAudioProcessingState.idle
:Minimal reproduction project
Official example: main.dart
Reproduction steps
Proper behavior:
Wrong behavior.
androidStopForegroundOnPause
to false.Output of flutter doctor
Devices exhibiting the bug
Google Pixel 8, Android 14 (AP2A.240705.005)
Context
I'm forced to use
androidStopForegroundOnPause = false
because my app can pause playback due to interruptions. After settingandroidStopForegroundOnPause = true
, my app can pause playback, but it getsForegroundServiceStartNotAllowedException
exception.The text was updated successfully, but these errors were encountered: