简体   繁体   中英

Android which is better for service stopself or never stopping it

I have in my project services that start only once and inside the service there is a thread that runs every second or so.

And then there is some services that after they finiah their procedure they call stopself and then they are started again for elsewhere.

My question is which of these structures are better for a service and why?

If you often start and finish Service, try using IntentService It automatically shuts down after work finished. Developer Guide

What k0sh said. If your service is running, it is using battery. If you don't need it running, stop it and save battery.

The difference between a running service and a stopped service is the likelihood that the process running it will be killed. A running service has a fairly high priority (low oom_adj). Android will try not to kill it off. A service that is not running has no affect on the priority of its owning process. If there is no other reason to keep that process around, Android will kill it, when it needs space.

Even a running service, though, will be reaped, eventually. There is no way to keep a process running forever.

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