如何检查,如果接收器被注册在安卓 [英] how to check if Receiver is registered in android

查看:217
本文介绍了如何检查,如果接收器被注册在安卓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的,如果不是我如何检查它的任何方法来检查,如果我注册的接收器仍然是注册?

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:

我想知道同样的事情。
  在我来说,我有一个的BroadcastReceiver 执行调用   上下文#unregisterReceiver(BroadcastReceiver的)传递自己作为处理其接收的意图后,ARG。
  有一个小的机会,接收器的的onReceive(上下文,意图)方法被调用   不止一次,因为它是注册多个 IntentFilters ,创造潜在的抛出:IllegalArgumentException 从<$ C被抛出$ C>上下文#unregisterReceiver(BroadcastReceiver的)。

I was wondering the same thing.
In my case I have a BroadcastReceiver implementation that calls Context#unregisterReceiver(BroadcastReceiver) passing itself as the arg after handling the Intent that it receives.
There is a small chance that the receiver's onReceive(Context, Intent) method is called more than once, since it is registered with multiple IntentFilters, creating the potential for an IllegalArgumentException being thrown from Context#unregisterReceiver(BroadcastReceiver).

在我来说,我可以存储私人同步成员呼吁上下文#unregisterReceiver(BroadcastReceiver的)前检查,但它会   如果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.

这篇关于如何检查,如果接收器被注册在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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