1

I am receiving

Fatal Exception: android.app.RemoteServiceException
can't deliver broadcast

in my app. I have broadcast receiver set in my activity. It is registered as

val filter = IntentFilter(Intent.ACTION_BATTERY_CHANGED)
val receiver = MyReceiver()
context.registerReceiver(receiver, filter)

here context refers to my activity context. When I searched for this exception, I saw posts saying that we should use

LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter)

When I changed the code to this statement, it doesn't enter my onReceive(). What is the right way to implement the same so that I can avoid this exception.

Thanks in advance.

Anju
  • 9,379
  • 14
  • 55
  • 94

1 Answers1

1

Assuming that you are seeing this in Sentry, Crashlytics, or some similar crash-reporting service, most likely you are seeing this bug. Reportedly it has been fixed, though we still see some devices that have not received the patch with the fix.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Yes, I saw this exception in crashlytics. In my case, this exception has occurred on Samsung devices with the Android 12 version. – Anju May 26 '23 at 12:46
  • 1
    @Anju: That's where I see it too. Fortunately, the frequency has been decreasing, though it is unlikely to ever reach zero. – CommonsWare May 26 '23 at 12:54
  • Is there any chance of increasing the crash count if we integrate the firebase remote config? @CommonsWare – Anju May 30 '23 at 04:47
  • 1
    @Anju: I do not see how Firebase Remote Config would impact the frequency of this crash. – CommonsWare May 30 '23 at 10:56
  • For the last update, this crash had gone up and we had this Firebase remote config feature newly added too. @CommonsWare – Anju May 30 '23 at 14:09