Like Java, Kotlin uses anonymous objects that implement functional interfaces to handle events. In this video, create new event handlers using Kotlin lambda expressions.
- [Instructor] Event handlers are incredibly … common in Android, … whether a system level event like a lifecycle event, … or an event triggered by a user gesture, … it's up to you to decide what happens … when an event occurs. … It's very easy to create event listeners in Kotlin. … Because Kotlin doesn't require as much … boilerplate code as Java, … Kotlin developers tend to make less use … or external libraries, such as Butterknife … that were originally developed … to counter Java's verbosity. … I'm going to work with this event handler … that's already present in my starting application. … This is creating a event listener object. … Now if this were Java, … you might see code that's creating an anonymous object … that implements an interface. … The interface has a single function … which receives a single argument, … sometimes known as a functional interface. … In Kotlin this code can be shrunk down enormously. … Now to see how much it's being shrunk, … I'm going to expand it a bit. …
Looking for study partners?Join the Associate Android Developer Exam study group
The Android app architecture constantly evolves. The introduction of the Kotlin programming language, new form factors such as Chromebooks, and reusable architecture components have made it faster and easier than ever to build high-quality Android apps. It is imperative that developers understand what the latest tools and recommendations are and how to use them to build out their applications. In this course, instructor David Gassner explains how to build an Android app that uses Kotlin instead of Java, add navigation functionality, and leverage the most useful architecture components such as LifecycleObserver, ViewModel, and LiveData, to create apps that are robust and easy to maintain over time.
- Handling lifecycle events
- Handling view events
- Updating display from new data
- Adding ViewModels to activities
- Subscribing to changes in LiveData values
- Adding a new launcher activity
- Starting activities with explicit intents
- Sharing data with implicit intents
- Adding a navigation drawer
- Adding a header to a navigation drawer
- Handling navigating drawer menu events