Why does the background service stops while running?

前端 未结 4 1378
别跟我提以往
别跟我提以往 2021-01-23 08:10

I have a background service in my android application.In which a thread listening recent tasks running frequently.My service overrides both onCreate() and onS

4条回答
  •  被撕碎了的回忆
    2021-01-23 08:36

    Android can stop any service at any time for any reason. A typical reason is low memory (killing the service to give its memory elsewhere), but I've seen at least a few devices that kill them every X hours regardless. There is no way to ensure you always run. The best you can do is have all your activities try to start your service (in case it isn't running), write your service so it can reload needed data, and set yourself as START_STICKY so if it has enough memory the framework will restart you later.

提交回复
热议问题