如何检查IntentService是否已启动 [英] How to check if an IntentService was started

查看:164
本文介绍了如何检查IntentService是否已启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一个活动是否成功启动了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆