简体   繁体   English

如何暂停服务

[英]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 在此处检查http://developer.android.com/reference/java/lang/Thread.html#sleep%28long%29

Enjoy. 请享用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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