In a well-architected Android app, the activity is only responsible for managing the user interface. In this video, update the UI based on data returned from a class' companion object function.
- [Instructor] I've previously described how to wrap … business logic in companion object functions … in Kotlin classes, now I'll demonstrate how to use … that code from a main activity class. … In my main activity, I've already declared an array … of image view objects, that are referencing … the die images in the activity layout. … I've also created a reference variable … that's pointing to this text view object, … that's the text at the top of the screen. … When the user clicks the floating action button … in the lower-right corner, I want to roll the dice … using the code in the DiceHelper class. … So I'll place this code inside my fabClickHandler function. … First I'll create a variable that I'll name dice … and I'll get its value by calling DiceHelper.rollDice. … So now I have a randomized integer array, … now I'm going to loop through the image view objects … and set the images one die at a time. … I'm going to use an iteration loop that starts … with a value of zero and goes until the size …
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