关闭android应用程序销毁广播接收器

时间:2013-04-10 21:47:17

标签: android

onCreate方法的主要活动中,我注册broadcastReciver,但当我关闭应用程序时,我总是收到此错误:

@429d47e0 that was originally registered here. Are you missing a call to unregisterReceiver()?
04-10 23:40:48.161: E/ActivityThread(20989):    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:793)
04-10 23:40:48.161: E/ActivityThread(20989):    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:593)
04-10 23:40:48.161: E/ActivityThread(20989):    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1274)
04-10 23:40:48.161: E/ActivityThread(20989):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1261)
04-10 23:40:48.161: E/ActivityThread(20989):    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1255)
04-10 23:40:48.161: E/ActivityThread(20989):    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:372)

当我关闭应用程序时,我不想取消注册接收器。我能做什么?我以编程方式注册接收器。

1 个答案:

答案 0 :(得分:4)

  

当我关闭应用程序时,我不想取消注册接收器

然后你不应该通过registerReceiver()注册它。请通过<receiver>元素在清单中注册。然后,无论您的应用程序是否正在运行,它都可用。