Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
Howdy Friends!
In Simple language Broadcast Receivers respond to broadcast messages from other applications or from the system itself. These messages are sometime called events or intents.
e.g an event is fire and if your application has a broadcast reciever then you can listen to the event and perform certain action like SMS Recievers (that responds when a SMS is delivered to the android system).
In this Blog we are going to create a local reciever that will respond to the local event created by our application.
This is a helper class to register for and send broadcasts of Intents to local objects within your process.
This helper class generate local events thus it will give you a much more efficient implementation (no cross-process communication needed) and allow you to avoid thinking about any security issues related to other applications being able to receive or send your broadcasts.
You can either dynamically register an instance of this class with Context.registerReceiver() or statically publish an implementation through the <receiver> tag in your AndroidManifest.xml.
Context.registerReceiver()
<receiver>
AndroidManifest.xml
Note: If registering a receiver in your Activity.onResume() implementation, you should unregister it in Activity.onPause(). (You won’t receive intents when paused, and this will cut down on unnecessary system overhead). Do not unregister in Activity.onSaveInstanceState(), because this won’t be called if the user moves back in the history stack.
Activity.onResume()
Activity.onPause()
Activity.onSaveInstanceState()
Let us now generate some events and receive in our Activity(s) receiver.
Step 1. Create a local event
Step 2. Create a Broadcast Receiver in the class where we want to perform an action
Step 3. Register and Unregister the broadcast receiver
Enjoy listening to the local events.
That’s all folk.. Stay Updated
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Excellent work, fast, good quality and understood the brief perfectly! Quick responses developing the project and very good cooperation. I suggest to anyone.
Stathis Plakidas
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.