泄露的IntentReceiver

时间:2013-12-22 22:12:30

标签: java android android-intent broadcastreceiver

我的onCreate()中包含以下代码:

registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

这一行似乎引发了以下错误:Activity has leaked IntentReceiver that was originally registered here. Are you missing a call to unregisterReceiver()?

我只是看不出这是怎么可能的 - 我完全卸载我的应用程序然后重新安装它,这是整个应用程序中唯一的接收器注册。有谁知道什么是错的?

1 个答案:

答案 0 :(得分:1)

您需要在onPause中取消注册接收器:

@Override
protected void onPause() {
  // Unregister since the activity is not visible
  LocalBroadcastManager.getInstance(this).unregisterReceiver(onComplete);
  super.onPause();
}