开发者

How to keep service alive?

Any application that has a service going obviousely counts on it to be always running. It's part of the product and if it's a paid app - the user expects it.

However, it seems that there is no way for a service not to get wacked if the Android OS feels the memory pressure or if something goes wrong and the ser开发者_如何转开发vice crashes.

What is the best way of making sure that a service is always running?

Is it wise to create a second service that once in a while start the "useful" service and if it's alredy running it'll be ignored?


To be honest, I am not sure if this is a good idea as all.

If there is enough memory pressure, it would not be fair towards other apps to insist on running. Also services only get kicked out on severe low memory situations.

If you write a reaper service, this one can get kicked out too.

And as you say " and if it's a paid app - the user expects it." -- the user also expects that apps play nicely


If your service is 'critical', you can use startForeground which gives your service as much priority as an Activity in the foreground.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜