Android Background Service is restarting when application is killed

前端 未结 7 2257
逝去的感伤
逝去的感伤 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:45

    I ran into the same problem and was able to resolve it by making the service run in a global process. You do this by adding the following to the manifest tag:

    process="com.myapp.ProcessName"

    (Make up whatever name.)

    When I did this I found that my service wasn't killed (and restarted) when the app is swiped off the list. Presumably this is because the app process is killed when you swipe it off, but global service processes are not.

    The disadvantage of this is that communication between your app and service now has to be via the IBinder interface; you can't directly call functions in the application or service from the other one, because they're running in different processes.

提交回复
热议问题