Events are handled in Android using callback methods. A callback method has a required signature that’s defined in a Java interface. For example, onClick events are handled by an interface named OnClickEventListener. It defines a single abstract method named onClick. To handle an event with Java code, you create an anonymous implementation of that interface, and then add your custom code to the method.
- [Instructor] Events are handled…in Android using callback methods.…A callback method has a required signature…that's defined in a Java interface.…As I described earlier,…you can designate a method to be called by the framework…by simply naming it in an XML layout file.…It's then called by the framework…and it is a callback method.…It must have a specific signature.…But you can also set up all…of your event handlers using pure Java code.…For example on click events are handled…by an interface named on click Event Listener.…
That interface defines a single…abstract method named on click.…To handle the event with Java,…you create an anonymous implementation…of the interface and then add…your custom code to the method.…I'll demonstrate this in the project JavaHandlers.…Now I'm picking up where the previous exercise left off…and I'm going to start by taking away…some of the code I created.…I'll go to my XML layout file…and remove the on click event handlers from there.…Then I'll come back to the main activity class.…
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