如何检查IntentService是否已启动 [英] How to check if an IntentService was started
问题描述
我想知道一个活动是否成功启动了IntentService
.
I'd like to get to know if an Activity successfully started an IntentService
.
由于可以通过bindService()
绑定IntentService
来保持其运行,也许一种方法是检查调用startService(intent)
是否导致在服务对象中调用onStartCommand(..)
或onHandleIntent(..)
.
As it's possible to bind an IntentService
via bindService()
to keep it running, perhaps an approach would be to check if invoking startService(intent)
results in a call of onStartCommand(..)
or onHandleIntent(..)
in the service object.
但是我如何在活动中检查呢?
But how can I check that in the Activity?
推荐答案
我想知道一个Activity是否成功启动了IntentService.
I'd like to get to know if an Activity successfully started an IntentService.
如果在调用startService()
时活动或服务中都没有异常,则IntentService
已启动.
If you don't get an exception in either the activity or the service when you call startService()
, then the IntentService
was started.
因为可以通过bindService()绑定IntentService使其保持运行状态
As it's possible to bind an IntentService via bindService() to keep it running
为什么?
这篇关于如何检查IntentService是否已启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!