Android广播接收器注册问题:Causedby:java.lang.Ille
发表时间:2021-1-10
发布人:葵宇科技
浏览次数:83
1、程序中明明使用如下方法进行了广播的注册和解除注册:
mContext.registerReceiver(downloadReceiver, filter); mContext.unregisterReceiver(downloadReceiver);
但程序运行过程中还是有一下问题:
android.app.IntentReceiverLeaked: Activity *********** has leaked IntentReceiver *********** that was originally registered here. Are you missing a call to unregisterReceiver()?
并出现报错:
Caused by: java.lang.IllegalArgumentException: Receiver not registered: ***************
后来改成下面方法就可以了:
mContext.getApplicationContext().registerReceiver(downloadReceiver, filter); mContext.getApplicationContext().unregisterReceiver(downloadReceiver);