androidkotlinexceptionbroadcastreceiverlocalbroadcastmanager

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


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.


Solution

  • 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.