一个非常奇怪的错误...我在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
答案 0 :(得分:1)
我认为你所获得的exeption不会从你的代码中抛出,甚至不会从Activity类代码抛出,而是在某个系统级库中创建,因此无法正确处理它。
在这里您可以找到解决方法: Android - BroadcastReceiver unregisterReceiver issue (not registered)
答案 1 :(得分:1)
如果您使用的是本地广播,请尝试使用
onPause(){
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
}