简体   繁体   中英

Is Android Service Supposed to Run After Manually Force Stopping Activity?

Context: I am attempting to test whether an Android Service is supposed to continue running in the background even after destroying the Activity via the Menu>Settings>Applications>Manage Applications>App_Name>Force Stop.

As of now my app successfully launches the service on boot-up, and appears to be working when left alone for a long period of time (around an hour). Yet my potential worry arises from "Force Stopping" the appplication, which also kills the service.

Question: Is the service supposed to continue to run even after "Force Stopping" the application?

Thanks so much for your help.

否。强制停止预计将停止所有应用程序活动,包括runinng Services和AsyncTasks

I have a similar situation where I start a service at boot up by registering to "BOOT_COMPLETED" intent. Then the onStartCommand ends by returning "START_STICKY" to make sure it always run eventhough nobody is bound to the service. Then, I create an activity that will bind to that service whenever it's running. In such case, killing the activity will not affect the service that started at boot time. In my case it works beautifully and I'm happy with it. The inconvenient of that is you end up with 2 "apk" instead of only one. In my case it was not a problem but I don't know if it's a problem for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM