I’m write an auto-speaker app which has a service inside, and listen to the phone state change.
I expect that the service should be exist all the time and can’t be killed.
However, I found that if I use some task killer to kill my app, there will be few seconds my listener won’t work.
Although my app seems to be restart automatically in few seconds later and work again.
Why the service could still be killed by task killer??
Is a service just like an activity, just with no UI, and able to restart automatically?
Thanks for your answer.
You cannot exempt your service from being ended by the user or automatically by the OS when resources are needed for that matter.
The best you could do is attempt to write code to compensate for restarts but certainly don’t write as if your service will run forever without exception.
EDIT
Android Developer documentation Managing the Lifecycle of a Service has useful information on recovering from stops and when the callback hooks get called and not.