简体   繁体   中英

How to pause a service

I look around but I couldn't find a strict answer. Is it possible to pause a service? or let him wait/sleep?

Thanks.

EDIT for more details: I have a button on my activity that stop/start my service. I would like to be able to pause my service and resume him and when my activity is shutted down only then to stop my service. So is it possible to pause a service?

A service is a process running in another thread. So, to pause a service (Thread), simply do

Thread.sleep();

Check here http://developer.android.com/reference/java/lang/Thread.html#sleep%28long%29

Enjoy.

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