-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
android.app.ForegroundServiceStartNotAllowedException: startForegroundService() not allowed due to mAllowStartForeground false #996
Comments
@serhii-k With the above steps, My app is working fine. |
See #932 (comment) and let me know if it works for you. If it does, I'll reflect this suggestion in the README. |
@ruchit-7span @ryanheise If I understand correctly from the plugin code:
Or maybe some other more elegant, well thought solution... But that is really something that can be accounted... |
I believe there is another feature request and pull request to make (4) possible but there is no settled-upon API design for it yet. That said, I agree the ideal is to set And although disabling the battery optimisation will prevent the exception, you're saying that it would also be good to stop the exception from happening in all cases, even if the battery optimisation is not disabled. Am I understanding that correctly? |
@ryanheise Yes, if we aren't stopping the foreground service during I completely agree that to make (4) possible there should be some good API. Argh... Android makes things so ugly as usual... |
Unfortunately, I'm baffled as to why this exception occurs at all, because that Android documentation you linked to seems to indicate that we are one of the exemptions. I've tried to look into it deeply before but came up with nothing (except for programmatically sending users to the settings to disable battery optimisation). |
Commented in the related issue: #994 (comment) |
I'm also getting this error although only sporadically. I haven't found a simple reliable reproduction method for it yet. Maybe something along these lines would help? |
That's an interesting approach... I haven't encountered the AlarmManager solution before. |
I'm not sure if that makes sense but it would be great if there was at least some way to catch this error. As it is now the whole app dies. Thanks for all your work on audio_service and just_audio by the way! They're a huge time saver. |
I could look into that as a fallback in case the app doesn't implement other measures to avoid the exception. |
That would be much appreciated! There's no way I can wrap my own exception handler around this now in my own code, right? |
The Please try it out and let me know if it works. Alongside that, the recommended solution is still to change the battery optimisation settings. The next thing I'd like to investigate is what influence the processing states might have on things. |
I would like to avoid solutions based on I can see two options:
I think the first option seems to provide more flexibility, but is too prone to misuse because people who are new to this will forget to set it and wonder why their app is not working. Thoughts? |
The I agree that crashing the entire app on an uncaught exception is a questionable design choice in the Android APIs. |
I've just merged and published the I will keep this issue open pending a feedback on the ideas suggested in #996 (comment) |
Documented behaviour
On Android 12+ it's not permitted to start a foreground service from the background.
Actual behaviour
Please follow the reproduction steps for a clear demonstration how to achieve this exception.
Precondition: the app is playing an audio in the background.
If we listen to the AudioSession.interruptionEventStream, and we pause for "begin" of the AudioInterruptionType.pause, and then we resume for "!begin". At this moment the exception happens. For some reason there is an attempt to start a foreground service (which actually is already running...) from the background.
Minimal reproduction project
Official example: example_multiple_handlers.dart
Reproduction steps
The steps should be done pretty fast, or you can add more numbers to say.
a) If you have new gestures (a horizontal bar at the bottom of the screen). Drag from the left bottom corner of the screen to the center of the screen.
b) If there are old 3 buttons. Press and hold the middle "Circle" button.
Output of flutter doctor
Devices exhibiting the bug
Android Emulator API Level 33 x86_64 (with Google Play)
The text was updated successfully, but these errors were encountered: