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

Fixed - foreground services are killed by the OS but there is a catch #1297

Open
cj-marius-duna opened this issue Oct 14, 2024 · 2 comments
Open

Comments

@cj-marius-duna
Copy link

cj-marius-duna commented Oct 14, 2024

Android 12 and later versions are designed to terminate foreground services automatically after days or weeks.

09-17 08:02:23.129  2670  2818 W ActivityManager: Exception when unbinding service com....otm.v3/com....otm.vpn.service.FilterService
09-17 08:02:23.129  2670  2818 W ActivityManager: android.os.DeadObjectException

If you check the logs and your service was a STICKY one, the ActivityManager is automatically restarting it with the following kill reason:
ActivityManager: Rescheduling restart of crashed service com.cujo.otm.v3/.service.CujoService in 9967ms for mem-pressure-event - mem pressure is the reason in my case. Just follow the LogCat and find yours

This means that the onStartCommand has already been called, but with a null intent.
In this situation, you will need to manually reinitialize everything.

@cj-marius-duna cj-marius-duna changed the title Fixed - foreground services are killed by the OS but there is a solution Fixed - foreground services are killed by the OS but there is a catch Oct 15, 2024
@Duna
Copy link

Duna commented Oct 15, 2024

Spend 2 weeks for finding this behaviour. Thank me later

@petrnalevka
Copy link
Collaborator

Hello @Duna @cj-marius-duna .. in my opinion this is nothing special in Android 12.. this is how FGS (or in earlier Android simply Services) worked on from the well "beginning". Even when the the service was sticky system may restart the service any time when memory is getting low and you need to cope with that in the code... for instacne expect intent to be null or expect a flow when onCreate is not called in the lifecycle but only onStartCommand...

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

No branches or pull requests

3 participants