MVVM on Android

Sep 1 2022 · Kotlin 1.6, Android 12, Android Studio Chipmunk | 2021.2.1 Patch 1

Part 1: MVVM on Android

01. Introduction

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Next episode: 02. Understand MVVM

Notes: 01. Introduction

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.

Transcript: 01. Introduction

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.