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);
service:
Caused by: java.lang.IllegalArgumentException: Service not registered : com.broadcom.bt.app.settings.ServiceExtraSettingsActivity@414e11e0 at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:923) at android.app.ContextImpl.unbindService(ContextImpl.java:1234) at android.content.ContextWrapper.unbindService(ContextWrapper.java:405) at com.broadcom.bt.app.settings.ServiceExtraSettingsActivity.onPause(ServiceExtraSettingsActivity.java:169) at android.app.Activity.performPause(Activity.java:5108) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1225) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2838) ... 12 more 方式1:
getApplicationContext().res
方式2: 服务未注册,看到其他博客上是用this.getApplicationContext去获取的bindservice 但为了保险起见,我的做法是设置一个布尔型的变量 1、private boolean isBind = false ; 2、isBind = bindService(svcMgrIntent, this, Context.BIND_AUTO_CREATE); 3、if (isBind) { unbindService(this); isBind = false;
}