1

一个非常奇怪的错误...我在 onResume() 和 onPause() 方法中注册和取消注册接收器。这是 onStop() 方法中的代码:

    try{
        this.unregisterReceiver(this.sdCardReceiver);
    }catch(IllegalArgumentException e){
        Log.d(MyOwnLife.LOG_LIFEGALLERY, "ActivityVideo - onStop unregisterReceiver:"+e);
    }

我收到以下错误:

Caused by: java.lang.IllegalArgumentException: Receiver not registered: myownlife.pigeau.activityVideo.ActivityVideo$SdCardReceiver@405443f8

我发现了错误……但我的应用程序还是崩溃了……知道吗?

这是完整的日志:

    java.lang.RuntimeException: Unable to stop activity {myownlife.pigeau/myownlife.pigeau.activityVideo.ActivityVideo}: java.lang.IllegalArgumentException: Receiver not registered: myownlife.pigeau.activityVideo.ActivityVideo$SdCardReceiver@405443f8
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2434)
at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:2506)
at android.app.ActivityThread.access$1900(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Receiver not registered: myownlife.pigeau.activityVideo.ActivityVideo$SdCardReceiver@405443f8
at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:610)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:851)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:342)
at myownlife.pigeau.activityVideo.ActivityVideo.onStop(ActivityVideo.java:224)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1170)
at android.app.Activity.performStop(Activity.java:3884)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2431)
... 11 more
4

2 回答 2

1

我假设你得到的异常不是从你的代码中抛出的,甚至不是从 Activity 类代码中抛出的,而是在某个系统级库中创建的,所以没有办法正确处理它。

在这里您可以找到解决方法: Android - BroadcastReceiver unregisterReceiver 问题(未注册)

于 2013-03-24T12:16:33.327 回答
1

如果您使用的是本地广播,那么试试这个

 onPause(){
  LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
  }
于 2014-11-22T22:28:05.540 回答