lixplor / android-Q-A

🐞 android related questions and answers
0 stars 0 forks source link

在一个BroadcastReceiver子类中, 用代码注册另一个receiver抛出ReceiverCallNotAllowedException #18

Closed lixplor closed 7 years ago

lixplor commented 7 years ago

在一个BroadcastReceiver子类中, 用代码注册另一个receiver抛出ReceiverCallNotAllowedException

lixplor commented 7 years ago

原因: 在BroadcastReceiver子类中不能直接使用context对象调用注册方法, 可能生命周期不同 解决: 可以使用context.getApplicationContext()得到的context对象调用注册方法