AntoineP
AntoineP

Reputation: 3073

IllegalArgumentException not catched

A very strange error...I register and unregister a receiver in the onResume() and onPause() methods. Here is the code in the onStop() method:

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

And I get the following error:

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

I catch the error...but my application crashes anyway...any idea ?

Here is the full log:

    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

Upvotes: 1

Views: 2907

Answers (2)

avinash
avinash

Reputation: 1774

If you are using a local broadcast then try this

 onPause(){
  LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
  }

Upvotes: 1

piotrpo
piotrpo

Reputation: 12636

I assume that exeption you have got is not thrown from your code, or even from Activity class code, but has been created at some system level library, so there is no way to handle it properly.

Here you find workaround: Android - BroadcastReceiver unregisterReceiver issue (not registered)

Upvotes: 1

Related Questions