BroadcastReceiver Tutorial Part 2 – DYNAMIC RECEIVERS – Android Studio Tutorial


In part 2 of the BroadcastReceiver tutorial, we will learn how to register a BroadcastReceiver dynamically. Instead of putting the receiver into the Manifest file, we register it in the lifecycle of our application. This way the BroadcastReceiver lives as long as the context where we register it in. This could be the application context itself, which would keep our BroadcastReceiver running as long as our app is running, but also for example the activity context or only as long as our app is in the foreground.
For this we have to call the registerReceiver method in any of the lifecycle callback methods (onCreate, onStart, onResume) and unregisterReceiver in their appropriate counterpart (onDestroy, onStop, onPause).
When we register our BroadcastReceiver, we also have to pass an IntentFilter, which specifies the action we are listening for.
Within the onReceive method of the BroadcastReceiver, we can also obtain data that is sent as an extra over the broadcast intent.

Watch the whole playlist:

Example code:

❗ Subscribe to the channel:

⏯ Watch more tutorials:

⭐ Become a channel member for exclusive tutorials and other perks:

㊙ Help translating the videos:

💚 Support the content:

💬 Join the Discord chat:

🎧 Audiobooks and podcasts for programmers:

👶 How to get started with Android development:

📣 Follow Coding in Flow on social media:






Xem thêm bài viết khác:


  1. Thank you so much man, 8 hours i tried to find why it's not working and when i watch your video it's help me man. THANK YOUUUU!!!!

  2. brother my phone is api21 i ran ur code i connect and disconnect wifi on both cases i get connected toast message i have written and then copied ur code what could be the issue i dont understand

  3. You.. Sir.. are a great teacher indeed. Simplicity is very hard to achieve but you have attained that while explaining.. Thanks a lot..

  4. Where can I find the onCreate method of the application class? As said @4:10. Wouldn't that just be the MainActicity?

  5. Sir I have a screen recording app. I want to start, pause and stop recording from notification action buttons. Which broadcast reciever would be the best for me ? Thank you in advance..

  6. Best Tutorials on YouTube I think, congrats. But I have one question: How can I REPLACE the TOAST with a SNACKBAR in the Receiver?? Can you send us/me a Solution for this?? In the Receiver is no VIEW, how can we do it work??

  7. How to listen to the action boot completed here ?
    Through add action method ?
    Should i add 1 more intent filter for that ?

  8. Sorry, I didn't understand if this dynamic receiver is still an implicit receiver. I need two examples of implicit broadcast receivers for my homework, and if in part one you showed us a static implicit broadcast receiver, here in part two we have a dynamic receiver, but I cannot understand if it is also implicit or not.( i thought no, because you said that in order to have an implicit broadcast receiver, we should write in the manifest file, and here we don't. yet only in the tutorial part 4 you said we were going to see explicit broadcast receivers).
    So my main simple question is:
    Could you please clear this for me? Thank you so much!

  9. Thanks! u great . I think if you go through little bit slow in speak that will be more interesting for our sub-continent . Whatever thanks a lot

  10. Dude, on 0:32 "connectivity_change" doesnt work for newer* versions …

  11. thanks, I like the tutorial. Do you have any tutorial on java web development with spring boot I want to learn it but I haven't found good tutorials

  12. Sorry I was ill a little bit so i couldn't watch video and do programming, but now i am alright and ready to try new things.


Please enter your comment!
Please enter your name here