java.lang.IllegalArgumentException: Receiver not registered : Android BroadcastReceiver

     --------- beginning of crash

2021-06-29 14:58:18.780 16932-16932/com.example.myapplication2 E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.example.myapplication2, PID: 16932

    java.lang.IllegalArgumentException: Receiver not registered: com.example.myapplication2.Activities.Affirmation.ShowAffirmationActivity$broadcastReceiver$1@94b6d81

        at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:1433)

        at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1553)

        at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:674)

        at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:674)

        at com.example.myapplication2.Activities.Affirmation.ShowAffirmationActivity.unregisterReciever(ShowAffirmationActivity.kt:90)

        at com.example.myapplication2.Activities.Affirmation.ShowAffirmationActivity$broadcastReceiver$1.onReceive(ShowAffirmationActivity.kt:36)

        at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)

        at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)

        at android.os.Handler.dispatchMessage(Handler.java:107)

        at android.os.Looper.loop(Looper.java:224)

        at android.app.ActivityThread.main(ActivityThread.java:7562)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

2021-06-29 14:58:18.784 16932-16932/com.example.myapplication2 E/MQSEventManagerDelegate: failed to get MQSService.

2021-06-29 14:58:18.786 16932-16932/com.example.myapplication2 E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler

    java.lang.IllegalArgumentException: Receiver not registered: com.example.myapplication2.Activities.Affirmation.ShowAffirmationActivity$broadcastReceiver$1@94b6d81

        at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:1433)

        at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1553)

        at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:674)

        at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:674)

        at com.example.myapplication2.Activities.Affirmation.ShowAffirmationActivity.unregisterReciever(ShowAffirmationActivity.kt:90)

        at com.example.myapplication2.Activities.Affirmation.ShowAffirmationActivity$broadcastReceiver$1.onReceive(ShowAffirmationActivity.kt:36)

        at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)

        at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)

        at android.os.Handler.dispatchMessage(Handler.java:107)

        at android.os.Looper.loop(Looper.java:224)

        at android.app.ActivityThread.main(ActivityThread.java:7562)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)


Explanation:

I am using directly unregisterReceiver(broadcastReceiver).

It's throwing error java.lang.IllegalArgumentException: Receiver not registered. You can check error in detail above.


Solution:

Use below to unregisterReceiver your local broadcast receiver.

LocalBroadcastManager.getInstance(this@ShowAffirmationActivity).unregisterReceiver(broadcastReceiver)

I have registered broad cast receiver in onCreate using below code.
LocalBroadcastManager.getInstance(this@ShowAffirmationActivity).registerReceiver(broadcastReceiver, IntentFilter(ACTION_FINISH_ALARM_ACTIVITY))

I have declared broad cast receiver at start of activity as shown below. This code only receives broad cast once and unregister broadcast receiver before finishing activity. This works perfectly fine. 
private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d("ACTION_FINISH_ALARM::", "Status::"+intent.action)
if (ACTION_FINISH_ALARM_ACTIVITY.equals(intent.action)) // 1 == lock
{
unregisterReceiver()
alarmOptions?.stopVibrationAndRinging()
finishAndRemoveTask()
}
}
}

java.lang.IllegalStateException at android.media.MediaPlayer : Android MediaPlayer Error

     --------- beginning of crash

2021-06-29 12:40:18.925 2968-2968/com.example.myapplication2 E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.example.myapplication2, PID: 2968

    java.lang.RuntimeException: Unable to stop service com.example.myapplication2.Util.AffirmationRingtoneService@4ce3875: java.lang.IllegalStateException

        at android.app.ActivityThread.handleStopService(ActivityThread.java:4201)

        at android.app.ActivityThread.access$2000(ActivityThread.java:224)

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)

        at android.os.Handler.dispatchMessage(Handler.java:107)

        at android.os.Looper.loop(Looper.java:224)

        at android.app.ActivityThread.main(ActivityThread.java:7562)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

     Caused by: java.lang.IllegalStateException

        at android.media.MediaPlayer._stop(Native Method)

        at android.media.MediaPlayer.stop(MediaPlayer.java:1418)

        at com.example.myapplication2.Util.AffirmationRingtoneService.stopMediaPlayerAfterAlarmFire(AffirmationRingtoneService.kt:72)

        at com.example.myapplication2.Util.AffirmationRingtoneService.onDestroy(AffirmationRingtoneService.kt:81)

        at android.app.ActivityThread.handleStopService(ActivityThread.java:4177)

        at android.app.ActivityThread.access$2000(ActivityThread.java:224) 

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924) 

        at android.os.Handler.dispatchMessage(Handler.java:107) 

        at android.os.Looper.loop(Looper.java:224) 

        at android.app.ActivityThread.main(ActivityThread.java:7562) 

        at java.lang.reflect.Method.invoke(Native Method) 

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 

2021-06-29 12:40:18.931 2968-2968/com.example.myapplication2 E/MQSEventManagerDelegate: failed to get MQSService.

2021-06-29 12:40:18.932 2968-2968/com.example.myapplication2 E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler

    java.lang.RuntimeException: Unable to stop service com.example.myapplication2.Util.AffirmationRingtoneService@4ce3875: java.lang.IllegalStateException

        at android.app.ActivityThread.handleStopService(ActivityThread.java:4201)

        at android.app.ActivityThread.access$2000(ActivityThread.java:224)

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)

        at android.os.Handler.dispatchMessage(Handler.java:107)

        at android.os.Looper.loop(Looper.java:224)

        at android.app.ActivityThread.main(ActivityThread.java:7562)

        at java.lang.reflect.Method.invoke(Native Method)

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

     Caused by: java.lang.IllegalStateException

        at android.media.MediaPlayer._stop(Native Method)

        at android.media.MediaPlayer.stop(MediaPlayer.java:1418)

        at com.example.myapplication2.Util.AffirmationRingtoneService.stopMediaPlayerAfterAlarmFire(AffirmationRingtoneService.kt:72)

        at com.example.myapplication2.Util.AffirmationRingtoneService.onDestroy(AffirmationRingtoneService.kt:81)

        at android.app.ActivityThread.handleStopService(ActivityThread.java:4177)

        at android.app.ActivityThread.access$2000(ActivityThread.java:224) 

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924) 

        at android.os.Handler.dispatchMessage(Handler.java:107) 

        at android.os.Looper.loop(Looper.java:224) 

        at android.app.ActivityThread.main(ActivityThread.java:7562) 

        at java.lang.reflect.Method.invoke(Native Method) 

        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 

Google Keep stopping - com.google.android.apps.gsa.tasks.m: EXCLUSIVE background task UPDATE_HOTWORD_MODELS crashed.


 com.google.android.apps.gsa.tasks.m: EXCLUSIVE background task UPDATE_HOTWORD_MODELS crashed.

at com.google.android.apps.gsa.tasks.n.ga(SourceFile:7)

at com.google.android.libraries.gsa.k.a.n.ga(SourceFile:2)

at com.google.common.w.a.bv.run(SourceFile:6)

at com.google.android.apps.gsa.shared.util.c.a.bt.b(SourceFile:1)

at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:1)

at com.google.android.libraries.g.aa.run(SourceFile:1)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)

at com.google.android.libraries.g.m.run(Unknown Source:2)

at com.google.android.libraries.g.e.run(Unknown Source:2)

at java.lang.Thread.run(Thread.java:919)

Suppressed: com.google.android.apps.gsa.shared.util.c.a.bv: Unchecked exception happened while running task: n[UPDATE_HOTWORD_MODELS-failure-handler]

at com.google.android.apps.gsa.shared.util.c.a.bw.run(SourceFile:6)

... 6 more

Caused by: com.google.android.apps.gsa.tasks.k: java.lang.IllegalArgumentException: Multiple entries with same key: en-AE=https://www.gstatic.com/android-search/hotword/x_google/9b74550b2fb24680fdac9ec59c56e828/hotword.data and en-AE=https://www.gstatic.com/android-search/hotword/x_google/9b74550b2fb24680fdac9ec59c56e828/hotword.data

at com.google.android.apps.gsa.tasks.b.c.b(SourceFile:2)

at com.google.android.apps.gsa.tasks.b.a.a(Unknown Source:4)

at com.google.android.libraries.gsa.k.a.g.a(Unknown Source:2)

at com.google.common.w.a.dr.a(SourceFile:1)

at com.google.common.w.a.co.run(SourceFile:4)

at com.google.common.w.a.dt.run(SourceFile:1)

... 6 more

Caused by: java.lang.IllegalArgumentException: Multiple entries with same key: en-AE=https://www.gstatic.com/android-search/hotword/x_google/9b74550b2fb24680fdac9ec59c56e828/hotword.data and en-AE=https://www.gstatic.com/android-search/hotword/x_google/9b74550b2fb24680fdac9ec59c56e828/hotword.data

at com.google.common.b.ps.v(SourceFile:1)

at com.google.common.b.ps.g(SourceFile:20)

at com.google.common.b.ps.e(SourceFile:6)

at com.google.common.b.gx.b(SourceFile:1)

at com.google.android.apps.gsa.shared.speech.hotword.c.a(SourceFile:9)

at com.google.android.apps.gsa.speech.hotword.b.a.a(SourceFile:8)

at com.google.android.apps.gsa.speech.hotword.b.a.b(SourceFile:3)

at com.google.android.apps.gsa.staticplugins.microdetection.b.p.e(SourceFile:1)

at com.google.android.apps.gsa.staticplugins.microdetection.b.p.b(SourceFile:2)

at com.google.android.apps.gsa.staticplugins.microdetection.b.p.a(SourceFile:28)

at com.google.android.apps.gsa.tasks.b.c.b(SourceFile:1)

... 11 more


Popular Posts