
如何检查后台服务是否正在运行?
我想要一个能够切换服务状态的Android活动 – 它可以让我打开它,如果它打开则关闭.
解决方法:
不久前我遇到了同样的问题.由于我的服务是本地的,我最终只是在服务类中使用静态字段来切换状态,如Hackbod here所述
编辑(记录):
这是Hackbod提出的解决方案:
总结If your clIEnt and server code is part of the same .apk and you are
binding to the service with a concrete Intent (one that specifIEs the
exact service class), then you can simply have your service set a
global variable when it is running that your clIEnt can check.We deliberately don’t have an API to check whether a service is
running because, nearly without fail, when you want to do something
like that you end up with race conditions in your code.
以上是内存溢出为你收集整理的如何检查服务是否在Android上运行?全部内容,希望文章能够帮你解决如何检查服务是否在Android上运行?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)