开发者

Need notification if Android closes Service

In several apps we use local services to (for example) record locations. This is working perfect for some time (e.g. 4 hours or 150km) and then A开发者_开发知识库ndroid closes (no longer wants) the service. The service is not crashing it's Android that decides to close the service.

It's written in the docs and it's ok BUT I need to find out that a service has been closed. How can I do that?

I would like to restart our service as soon as possible. How do you guys find out that a service has been closed by Android? Do you use finalize?

Thanks in advance.


Have you tried to return Service.START_STICKY or Service.START_REDELIVER_INTENT from Service.onStartCommand() method?


Your service's onDestroy method should be called as it is destroyed by Android OS. Also you should see in logs that normally android re-boots your service after a short time period, which is shown in the logs as it is destroyed, in my experience its around 15-30 seconds before it is booted again. (Every service you have in your app will be booted in a random order so beware if some services rely on other services in your app.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜