zoukankan      html  css  js  c++  java
  • android.content.ReceiverCallNotAllowedException问题解决

    动态注册BroadcastReceiver时有时候会遇到这个异常:

    android.content.ReceiverCallNotAllowedException: BroadcastReceiver components are not allowed to register to receive intents

    注意以下两点:

    1. manifest下配置的broadcast receiver 内最好不好去register receiver.

    2. 自己也不要注册自己,比如 class A extends BroadcastReceiver, 然后A提供

    public class ATracker extends BroadcastReceiver {

    …………….

    ……..

    public void startTracker() {

            this.context.getApplicationContext().registerReceiver(this, filter);

        }

    …………

    ………….

    }

    注册时使用getApplicationContext()最好。

    参考资料(register函数说明最后一段):

    Note: this method cannot be called from a BroadcastReceiver component; that is, from a BroadcastReceiver that is declared in an application's manifest. It is okay, however, to call this method from another BroadcastReceiver that has itself been registered at run time with registerReceiver, since the lifetime of such a registered BroadcastReceiver is tied to the object that registered it.

  • 相关阅读:
    python字符串字典列表互转
    列表迭代器 ListIterator
    并发修改异常处理
    二月天 案例
    Calendar类
    Date类
    冒泡排序
    内部类
    python第三天
    Layui——checkbox使用
  • 原文地址:https://www.cnblogs.com/feitianlee/p/3890162.html
Copyright © 2011-2022 走看看