如何检查是否接收器采用的是Android注册? [英] How to check if Receiver is registered in Android?
问题描述
我需要检查,如果我注册的接收器还是登记如果不是我如何检查它的任何方法呢?
I need to check if my registered receiver is still registered if not how do i check it any methods?
推荐答案
我不知道直接通过API提供了一个API,如果你考虑的此线程:
I am not sure the API provides directly an API, if you consider this thread:
我想知道同样的事情。结果
在我来说,我有一个调用广播接收器
实施
上下文#unregisterReceiver(广播接收器)
传递本身处理它接收的意图后,ARG。结果
有一个小的机会,接收机的的onReceive(上下文,意图)
方法被调用
不止一次,因为它与多个注册 IntentFilters
,从而为潜在的抛出:IllegalArgumentException
从<$ C被抛出$ C>上下文#unregisterReceiver(广播接收器)。
I was wondering the same thing.
In my case I have aBroadcastReceiver
implementation that callsContext#unregisterReceiver(BroadcastReceiver)
passing itself as the arg after handling the Intent that it receives.
There is a small chance that the receiver'sonReceive(Context, Intent)
method is called more than once, since it is registered with multipleIntentFilters
, creating the potential for anIllegalArgumentException
being thrown fromContext#unregisterReceiver(BroadcastReceiver)
.
在我来说,我可以存储一个私人同步调用成员环境#unregisterReceiver(广播接收器)
前检查,但它会
如果API提供的检查方法更清洁。
In my case I can store a private synchronized member to check before calling Context#unregisterReceiver(BroadcastReceiver)
, but it would be
much cleaner if the API provided a check method.
这篇关于如何检查是否接收器采用的是Android注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!