Android-Service killed with “no longer want” - how to restart it?

前端 未结 2 857
执念已碎
执念已碎 2020-12-23 17:29

We have a Service that continuously collects sensor data on the phone. This service should run \"forever\", e.g. as long as the user wants, and not be killed by the system.<

相关标签:
2条回答
  • 2020-12-23 17:51

    Try overriding the onCreate() method of your service. If the service is killed and then restarted it's onCreate() is called, but not onStart(). So you can, for example, add call to onStart() from onCreate to make it behave like the RunKeeperService.

    0 讨论(0)
  • 2020-12-23 17:57

    How do you start the service? Have you tried startForeground()? That's not an absolute guarantee, of course, but should at least lengthen the lifespan.

    0 讨论(0)
提交回复
热议问题