Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(android): prevent RemoteServiceException$ForegroundServiceDidNotStartInTimeException #1202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ajitpatel28
Copy link

In this pr i've tried to handle the following raise condition:
when stopSelf() is called before startForeground then it will lead to a crash ->
Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{ab29442 u0 live.friend.dostt/app.notifee.core.ForegroundService c:live.friend.dostt}

To easily reproduce this crash just call the stopSelf() method before calling startForeground() method

solution:
we have to make sure to call startForeground before calling stopSelf(), for this, i've
added a dummy notification to ensure startForeground is always called before calling stopSelf(), with notification id 1.
This will prevent the crash ForegroundServiceDidNotStartInTimeException

 handled the  following raise condition:
when stopSelf() is called before startForeground then it will lead to a crash ->        
`Fatal Exception: android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{ab29442 u0 live.friend.dostt/app.notifee.core.ForegroundService c:live.friend.dostt}`

To easily reproduce this crash just call the `stopSelf()` method before calling `startForeground()` method 

solution:
we have to make sure to call `startForeground` before calling `stopSelf()`, for this, i've 
added a dummy notification to ensure `startForeground` is always called before calling `stopSelf()`, with `notification id 1`.
This will prevent the crash `ForegroundServiceDidNotStartInTimeException`
Copy link

docs-page bot commented Feb 9, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/notifee~1202

Documentation is deployed and generated using docs.page.

@CLAassistant
Copy link

CLAassistant commented Feb 9, 2025

CLA assistant check
All committers have signed the CLA.

@ajitpatel28 ajitpatel28 changed the title fix(android): ensure foreground service starts before stopSelf to pre… fix(android): prevent RemoteServiceException$ForegroundServiceDidNotStartInTimeException Feb 9, 2025
Copy link

Hello 👋, this PR has been opened for more than 2 months with no activity on it.

If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing!

You have 15 days until this gets closed automatically

@github-actions github-actions bot added the Stale label Mar 10, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants