You learned how to handle events triggered by user actions, but you can also listen for and handle events generated by the operating system and the application framework. These events are known in Android as Broadcast messages. You can listen for a broadcast message with a custom class that extends BroadcastReceiver. You can register these receivers either in the application manifest or with a bit of code in an activity’s onCreate() method.
- [Instructor] So far, I've focused on events…that are triggered by user actions.…But you can also listen for…and handle events that are generated…by the operating system and the application framework.…These events are known as broadcast messages.…You can listen for a broadcast message…with a custom class that extends…a class called BroadcastReceiver.…You can register to listen for these events,…either in the application manifest,…or with a bit of code in an activity's onCreate method.…I'm going to show you the code-based approach,…but encourage you to look at the documentation…to see how you can listen for these sort of events,…even when an activity isn't on the screen.…
I'm working in the project BroadcastMessages,…and I'll start off in the MainActivity.java file.…At the bottom of the file,…I'll add a new nested class…that I'll name MyBroadcastReceiver,…and I'll extend the class BroadcastReceiver…from the android.content package.…Now because that class has some required abstract methods,…I'll move the cursor back up here,…
David also shows how to send and receive broadcast messages that let you exchange data and notifications among the different tiers of your application. He demonstrates how to work with menus and the action bar, add a navigation drawer to a layout, and tackle advanced navigation techniques. Later courses in the Essentials series concentrate on other specific skills you can master.
- Working with events
- Handling events with Java objects and lambda expressions
- Managing navigation
- Sending data to an activity
- Opening other apps with implicit intents
- Sending and receiving broadcast messages
- Working with menus and the action bar
- Adding a navigation drawer
- Advanced navigation techniques
- Removing activities from the back stack