My Android service is stopping abruptly and a new one created

前端 未结 2 582
孤城傲影
孤城傲影 2021-01-28 14:07

I have a very simple Android GPS logging app that runs a service. The Activity is nothing but a start/stop button to control the service. On a button click, I start a new backgr

相关标签:
2条回答
  • 2021-01-28 14:31

    A Service is actually running in the main thread, and if you do work that could take some time you should create a new thread. Android can do this for you if you use an IntentService instead of the regular Service.

    I should add that Android will kill a process that occupie the main thread for more than 5(?)s. Locking the main thread will cause an ANR (Application Not Responding), and maybe this is what you experience in your Service.

    0 讨论(0)
  • 2021-01-28 14:51

    Android does not terminate a background service when its parent activity is closed. But it suspends background jobs when device screen is locked. Your problem may be related to this. When screen is unlocked again, the service is expected to continue its work from where it left.

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