Skip to content Skip to sidebar Skip to footer

Driving A Service Api From A Broadcastreceiver

I get an error message when I attempt to bind from the onReceive() of a receiver to a local service before I drive a bespoke API on it. 'IntentReceiver components are not allowed t

Solution 1:

What is the best way of getting a piece of data from a service while in a broadcast reciever.

If the BroadcastReceiver is created from something else (e.g., an activity) and set up with registerReceiver(), then the "something else" is what should be binding to the service and doing the work.

If the BroadcastReceiver is a component registered in the manifest, then you need to rethink your approach to whatever problem you are trying to solve. These sorts of BroadcastReceivers cannot bind to services and cannot spend much time doing work. If the BroadcastReceiver cannot do its work in less than, say, 10ms, it should delegate control to a service via startService(). That service can then do the work on a background thread.

P.S. I need to get the answer synchronously i.e. I have wait on the answer from the service

See above.

Post a Comment for "Driving A Service Api From A Broadcastreceiver"