A badly written code is a NIGHTMARE (when needed to maintain). For any developer there is nothing better than having a clean, structured code. And if you want to achieve this, you must follow a design pattern for your projects. So this Android MVVM Tutorial is for all the people out there who learned the basics of android development and now want to learn something advanced. Because if you are seeking a JOB then knowing only the basics are not enough. You should know some design patterns.
Table of Contents
What is MVVM?
MVVM stands for Model View ViewModel and it is a design pattern that is used to build softwares. But here our focus is only about Android App Development. MVVM helps us to separate the Business Logic of our Application from the Views or UI. And doing this thing is very important in case of any kind of software or app development.
Model : This is responsible for handling the data in the application. Model cannot directly interact with Views, but it interacts with ViewModels and then Views with the help of observables. (Sounds confusing right? Don’t worry in the course we will cover every step in detail).
View: This is the User Interface of our Application. It should not contain any application logic.
ViewModel: It is basically a link between Model and View.

MVVM in Android
When we want to use MVVM in Android, we use this architecture.

One more thing is involved here and that is the Repository. So repository is responsible for handling the data. Repository may use multiple data sources according to the need, it may fetch data from a Remote Source or from the local storage.
Advantages of using MVVM
Now let’s talk about what are the advantages of using MVVM in your android project.
- If you use MVVM it will help you structuring your code in a nice way so that it is easy to understand for a new developer.
- Using MVVM makes your project maintainable as everything is well organized and making changes are very easy.
- Testability is easy with MVVM because all modules are independent and testable.
- MVVM enhances the re-usability of the code.
Pre-Requisites of this Course
This course contains many advanced topic like creating repositories, dependency injection, data binding etc. And that is why this course is not for any beginner who just started learning android development. But if you sure you know the basics very well then you can give it a start.
Android MVVM Tutorial
Now, if you think you should learn about MVVM in android then, “What are you waiting for?”. Start now it is ABSOLUTELY FREE for everyone.
If you think this course is helpful and my efforts of creating this course worth something then I have a request that please SUBSCRIBE and tell your friends to SUBSCRIBE to my channel as well.
Android MVVM Tutorial – Source Code
You can check my source code while following the course. For every lecture I have a separate commit and you can browse the code for that commit only and it will make your learning better.
Android MVVM Tutorial Source Code Download

Hi, my name is Belal Khan and I am a Google Developers Expert (GDE) for Android. The passion of teaching made me create this blog. If you are an Android Developer, or you are learning about Android Development, then I can help you a lot with Simplified Coding.
Sir Kindly make a course on MVVM (JAVA) as soon as possible.
By the way Thank you so much for your efforts.
sir please make a course on mvvm(java) as soon as possible
sir please make a course on mvvm(java) as soon as possible
Hi sir could you provide me source code as well. That will be very helpful
“I get an error ” – Could not resolve enqueue – MyApi().userLogin(email,password).enqueue()
I’m learning mvvm pattern now by watching your tutorial on YouTube but I’m having challenges with your baseUrl…I would like to know if that api is still up and running/valid
There was a problem for few days, but now its working fine you can check.
Hello bro, I trust you are doing ok.
Thanks for your video on using mvvm architecture.
It was very helpful.
I’m currently using it as a template on one of my projects.
Please I have a little issue when using the Authviewmodel and repository in getting access to a view.
I’m using the country picker library, and I would like to access the country code directly from the Authviewmodel class so that I can pass the code to the the UserRepository to make an API call.
I’ve been on this for 2 whole days, I think if I can get access to any view from the viewmodel I can instantiate the country code picker class and proceed.
Please I would really appreciate any help.
Thanks so much
Cannot watch your videos anymore as its telling to login using G suite Account. Please provide some solutions to this.
Sorry I didn’t get you, can you explain exactly whats happening?
Hello could you provide me source code as well. That will be very helpful
The source code link is already given in the post.
You have handled a success response but you did not handle error properly. what if an exception occurs here
private suspend fun fetchQuotes() {
val lastSavedAt = prefs.getLastSavedAt()
if (lastSavedAt == null || isFetchNeeded(LocalDateTime.parse(lastSavedAt))) {
try {
val response = apiRequest { api.getQuotes() }
quotes.postValue(response.quotes)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
How will you convey to through the view?
You can handle the error in catch block.
thank you for course but i can’t get source code
can you help me
Hi, your course is really very helpful, but even after subscribing to your channel, I am not able to download source code.
Please help me with your source code.
Can you explain in detail, like what issue you are facing?
Can you please explain what issue you are facing while downloading the code?
i subscribed your channel but still not able to download source code, Please help me .
Click the download link,
You will see the download page where link is locked, now follow these steps
#1 Click on Subscribe Button, it will open a new tab, in this tab subscribe if you are not already subscribed. If you are already subscribed ignore this tab and go back to the download page. Make sure you don’t open the download page again and go back to the already opened page.
#2 Wait for few seconds and the download link will unlock.
Could you please send us api source code of mvvm tutorial
abstract class SafeApiRequest {
suspend fun apiRequest(call:suspend()->Response):T{
var response=call.invoke()
if(response.code()==401||response.code()==422)
{
var error=response.errorBody().toString()
var message=StringBuilder()
error.let {
try {
message.append(JSONObject(it).getString(“message”))
}catch (e:JSONException){}
}
message.append(“\n”)
throw ApiInspection(message.toString())
}else{
return response.body()!!
}
}
}
class ApiInspection(message:String):IOException(message) {
}
I subscribed your channel but cannot access github link for this tutorial
Click the download link,
You will see the download page where link is locked, now follow these steps
#1 Click on Subscribe Button, it will open a new tab, in this tab subscribe if you are not already subscribed. If you are already subscribed ignore this tab and go back to the download page. Make sure you don’t open the download page again and go back to the already opened page.
#2 Wait for few seconds and the download link will unlock.
Hi,
I am unable to download the source code even after subscribing to the channel.
Click the download link,
You will see the download page where link is locked, now follow these steps
#1 Click on Subscribe Button, it will open a new tab, in this tab subscribe if you are not already subscribed. If you are already subscribed ignore this tab and go back to the download page. Make sure you don’t open the download page again and go back to the already opened page.
#2 Wait for few seconds and the download link will unlock.
The source code is not accessing even though I subscribed your channel. Please help to download the source code of MVVM kotlin.
I have profile API view and update called from different screen.
1.First view API called from one screen
2.updateAPI called another screen.
3.And then to update exist view ” view API “was called .it was solution
4.Any better solution available
I am trying to use room database with kotlin in my project and my response is something like this in below so i don’t know how the do this
[
{
“image”: “/images/8d079d68-91b4-41b9-9a9b-24b1366abab0_spweb.png”,
“url”: “/BP”
},
{
“image”: “/images/23741d5d-f88b-4815-baca-5d3f60195c07_flagship-hul-star_cleaning_essential-web-july2020-sbi.jpg”,
“url”: “/Cleaning”
},
{
“image”: “/images/87c70780-9d02-4134-8296-4a830debdd5b_msweb.png”,
“url”: “/MONSSON”
},
{
“image”: “/images/ba2167ab-024f-4094-8a09-2b04db093d37_flagship-tataq-1400×400-web-03072020.jpg”,
“url”: “/TATAQ”
}
]
Excellent tutorial combining MVVM, API, Room, data binding, view binding, and dependency injection with Kodein.
Hi sir,
I have gone through this tutorial regarding Kotlin, a few confusions are going to happen while implementing this MVVM source code
Getting an error in postman , Can you please give any suggestion or share the api
Plzzz Do course on mvc,mvp,mvvm(java) as soon as possible
yes plzzz Do course on mvp,mvc,mvvm(java) as soon as possible