I define BroadcastReceiver in an application manifest and the receiver receives events in onReceive as expected. However I do not create the receiver class so I can't pass any information about my activity which the receiver is supposed to control. Context parameter gives me only application context and no any activity reference. So what is right way to make communication between application activities and broadcast receiver?
Retrieve the current result extra data, as set by the previous receiver. This can be called by an application in onReceive(Context, Intent) to allow it to keep the broadcast active after returning from that function.
Currently there is no way to check if a receiver is registered using the receiver reference. You have to unregister the receiver and catch the IllegalArgumentException that is thrown if it's not registered. This is ugly, and a boolean method to check if it's registered would be helpful.
Step 1. Open your project where you want to implement this. Step 2. Open your BroadcastReceiver class from where you pass data to activity inside your onReceive() you need to start intent and pass data inside intent and start sendBroadcast() as shown bellow.
Register Broadcast: Statically (manifest-declared) - This receiver can be registered via the AndroidManifest. xml file.
The answer is a little twisted but I found it here as well Inform Activity from a BroadcastReceiver ONLY if it is in the foreground It seems working. Please close the question then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With