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.