Skip to content
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

ForegroundService not allowed crash happening in background for android 14 #23

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

GaneshHegdeSharechat
Copy link

@GaneshHegdeSharechat GaneshHegdeSharechat commented Dec 6, 2024

What problem do you get?
Fatal Exception: java.lang.RuntimeException
Unable to start service com.liulishuo.filedownloader.services.FileDownloadService$SharedMainProcessService@4f09cbf with Intent { cmp=../com.liulishuo.filedownloader.services.FileDownloadService$SharedMainProcessService (has extras) }: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service ../com.liulishuo.filedownloader.services.FileDownloadService$SharedMainProcessService

Crash is not reproducible, happening 100% background and 100% in Android 14.

Which version of FileDownloader are you using when you produce such problem?
Tried both 1.7.9 and 1.7.10.
Getting crashes in both.
How to reproduce such problem?
Only seeing it in Crashalytics and it is not reproducible locally
Related topic:
https://issuetracker.google.com/issues/307329994

Closes #22.

@GaneshHegdeSharechat GaneshHegdeSharechat changed the title fix for ForegroundService not allowed crash happening in background ForegroundService not allowed crash happening in background for android 14 Dec 6, 2024
@Goooler
Copy link
Owner

Goooler commented Dec 7, 2024

This is the restriction from Android 12, and you can't launch this service from the background. We shouldn't catch exceptions here, if you really need this, catch ForegroundServiceStartNotAllowedExceptions in your app's UncaughtExceptionHandler.

See:

@GaneshHegdeSharechat
Copy link
Author

GaneshHegdeSharechat commented Dec 9, 2024

This is the restriction from Android 12, and you can't launch this service from the background. We shouldn't catch exceptions here, if you really need this, catch ForegroundServiceStartNotAllowedExceptions in your app's UncaughtExceptionHandler.

See:

This is not because we are starting the foreground service from background.
This is mainly happening because of START_STICKY and as per the existing google issue tracker, this is a way to stop this crash from happening currently.

One of the other comments suggested to change START_STICKY to START_NOT_STICKY, but some are still saying that did not reduce the crash. So currently stopping the service for this exception is one of the solutions presented by developer relations enginner.

Reply from google for this crash. - https://issuetracker.google.com/issues/307329994#comment86
Screenshot 2024-12-09 at 11 53 36 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to start service com.liulishuo.filedownloader.services.FileDownloadService$SharedMainProcessService
2 participants