Watch this episode for free — or access the full course as a raywenderlich.com Subscriber. Learn more about the benefits of subscribing here
MVVM on Android
Part 1: MVVM on Android Introduction
— Android & Kotlin

Lesson Complete

Play Next Lesson
Next

Introduction Pro

This course was originally recorded in 2018. It has been reviewed and all content and materials updated as of July 2022.

One major change was removing Kotlin synthetics in favor of View Binding. The data binding episodes were removed from the update as there were some conflicts when using View Binding, plus LiveData does the job of observing changes well enough.

Another major change was replacing AsyncTask with Kotlin Coroutines so you’ll see some little difference for code that is run without blocking the current thread. Check the Resources and Updates tab, and download materials for places where those changes were made. You can locate these changes by searching for “Update Note” comments in your IDE.

Prerequisite include a good knowledge of Android development which includes how to work with activities, fragments and a good understanding of the lifecycle of an Android Activity.

Let’s review what you will be learning in this course, including a brief discussion of benefits of MVVM and the course sample project.

Contributors

Hello everyone, I’m Emmanuel and welcome to the MVVM on Android course.

A well structured Android app is really important as this improves your workflow as your app grows. This course covers how to implement the MVVM pattern which is one of the approaches you can use to structure your Android apps.

The original course was produced in 2018 but the core concepts still remains the same. I’ve gone through this course to make sure everything is working fine.

The major change in the download materials was updating the project to use viewBinding over the now deprecated Kotlin synthetics. The project was also updated to use Kotlin Coroutines over AsyncTask which is now deprecated.

It is important you read the author note of each episode before watching them to understand the changes.

That’s it from here. Over to you Joe.

Hey everyone! My name is Joe, and welcome to this course on Android MVVM.

MVVM stands for Model-View-ViewModel, and it’s one of the more popular patterns for structuring your Android app code. In this course, I’ll introduce you to the ideas of MVVM and you’ll get to use it hands-on inside an Android app project.

MVVM helps you separate your code into different layers that each have their own responsibilities. As opposed to, for example, putting most of your app code into Activity or Fragment classes.

By using MVVM, you make your code more readable, testable, and maintainable. These are key aspects of building a code base that stands the test of time and frequent app updates.

Creaturemon is the name of the sample project we’ll use in the course. The app lets you create characters to use in a Creaturemon game. You can assign Intelligence, Strength, and Endurance values to each character. The app calculates a resulting HitPoints value for the characters.

We’ll first build out the screen that lets you create new characters. We’ll walk though creating and testing the Model, which will be independent of the ViewModel and View layers. We’ll setup a repository to let you store character data in a Room database.

Next, we’ll create a ViewModel and add unit tests for the logic contained in the ViewModel. Then we’ll connect the ViewModel to the repository to allow you to save creatures into the app database.

You’ll then have a chance to try out what you’ve learned by creating a ViewModel for the screen that shows a list of all the characters.

There’s a lot to do, but before we dive into the code, let’s get started in the next video by taking a look at the ideas and concepts behind MVVM.

Reviews

Comments