Can a service be killed by a task killer

I am writing an auto speaker app that has a service inside and listen for a phone state change.

I expect the service to exist all the time and cannot be killed.

However, I found that if I use a task killer to kill my application, there will be a few seconds when my listener will not work.

Although my app seems to restart automatically after a few seconds and work again.

Why can a service be killed by a task killer?

Is the service the same as an activity, no UI and can restart automatically?

Thanks for your reply.

+2


source to share


3 answers


You cannot free your service from being terminated by the user or automatically by the OS when resources are needed.

The best thing you can do is try to write code to compensate for the restarts, but of course not write as if your service was running without exception.



EDIT

The Android developer documentation Service Lifecycle Management contains useful information on recovering from stops and when calls are called and not.

+3


source


Add this trick to your onCreate service:

startForeground(R.string.app_name, new Notification());

      



This will prevent low memory service from closing, task killing, etc.

+2


source


Because removing the ability of the user to terminate the process when he wants to is simply wrong. Instead, try writing a workaround so that XXXXXX occurs if the service is disabled.

0


source







All Articles