Android Background Service is restarting when application is killed

前端 未结 7 2255
逝去的感伤
逝去的感伤 2020-11-27 17:20

I am developing an application in which a background service is created to collect sensor data. I am starting the service from my activity:

startService(new          


        
7条回答
  •  执笔经年
    2020-11-27 17:23

    If you are using an IntentService, it has an

    onHandleIntent() 
    

    method where you should place the code that needs to be executed. It is executed in a separate thread (not a UI thread where your application runs) therefore your app shouldn't affect it. When the code has finished executing, the thread is terminated and the service is stopped automatically.

提交回复
热议问题