Room + ViewModel + LiveData + RecyclerView (MVVM) Part 1 – WHAT ARE ANDROID ARCHITECTURE COMPONENTS?


In this video series we will build a note taking app, using the Android Architecture Component libraries (Room, ViewModel, LiveData and LifeCycle), a RecyclerView and Java. The data will be stored in an SQLite database and supports insert, read, update and delete operations. For this we will follow the official recommendations from the “Guide to App Architecture” (link below).

In part 1 we will learn what the Architecture Components are, how they work and why we need them. We will learn about the problems that arise from the Activity and Fragment lifecycle, configuration changes and bloated, tightly coupled classes and how ViewModel and LiveData can help us with that.
ViewModels store and manage UI related data, they survive configuration changes and can be used seemlessly by the newly created activity. LiveData is an observable dataholder and it is life-cycle aware, which means it automatically starts and stops updating the UI-controller at the right times in it’s lifecycle.
For the backend of our app we will use the “Room Persistence Library”, which works as a wrapper around SQLite and helps us reduce boilerplate code by making extensive use of Annotations. Instead of creating an SQLiteOpenHelper, we simply turn Java classes into “entities” to create tables, and use “Data Access Objects” (DAO) to query these tables and make operations on them. Room also provides compile time verification for SQL statements, so we run into fewer runtime exceptions, caused by typos and invalid queries.
We will also use a “Repository” class that works as another abstraction layer between the ViewModel and the underlying data model.
Together, this whole structure constitues an “MVVM” (Model-View-ViewModel) architecture, which follows the single responsibility and separation of concerns principles.

Watch the whole playlist:

Official Guide to App Architecture:

❗ Subscribe to the channel:

⏯ Watch more tutorials:

⭐ Become a channel member for exclusive tutorials and other perks:

㊙ Help translating the videos:

💚 Support the content:

💬 Join the Discord chat:

🎧 Audiobooks and podcasts for programmers:

👶 How to get started with Android development:

📣 Follow Coding in Flow on social media:






Xem thêm bài viết khác:


  1. Hello everyone , I have learnt a lot from this channel hence providing some update while watching this playlist and I request creator to include a updated video.
    if you are learning MVVM using this playlist in June 2020 .
    then update few things as follows ,
    Use following dependencies

    // for lifecycle
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

    // for room
    implementation "$room_version"
    annotationProcessor "$room_version"

    Also one thing
    ViewModelProviders.of() method is deprecated now ,
    So use bellow code to create noteViewModel instance in your MainActivity

    noteViewModel=new ViewModelProvider.AndroidViewModelFactory(getApplication()).create(NoteViewModel.class);

    All these changes are working fine on latest android dependencies
    Thank You

  2. This is really helpful, great stuff thank you. Please can you do a tutorial on one to many relationship or nested relationship with how to use the foreign key in an entity please, Thank you

  3. Ich habe ein paar Fragen:
    Ist die Datenbank dann nur lokal auf dem Gerät? Was ist der unterschied zwischen die Daten auf einer Datenbank zu speichern und in Sharedpreferences? Stimmt es das es dass selbst wenn es Lokal ist immernoch effizienter ist die Daten vorübergehend im Cache zu speichern? Wenn ja dann hast du ein Tutorial dazu?

  4. Watching and following this tutorial, rewrite it to kotlin also using androidx and change asynctask to coroutines, you can visit the repo in this link

  5. Man, you are the best! this is just what i needed and i love the way you explain , so easily to understand , thank you! hope you doing good! greetings from México

  6. watching this 2 years later, and to be honest, this is the best android tutorial i've seen, it really is a hidden gem on youtube

  7. Hi, love your tutorials. Could you please make a MVVM app using Volley. I've looked for this everywhere and only found Retrofit. <3 Thank you!

  8. Here is the original codelabs project

    With Kotlin

    With Java

  9. das hier ist verdammt gut. Vielen vielen Dank. Super erklärt, keine überflüssige Information, einfach was man erwartet. Klarttext formuliert. Super dass du es auf Englisch gemacht hast, es nervt total wenn man die ganze Zeit "Ersatzbegriffe" auf Deutsch lernt. So kann man auch einfacher googlen. Geil im wahrsten sinn des Wortes!

  10. Hey, I was wondering as per LiveData concept, if there is a change in an API Data then automatically all the ones who are observing the Livedata will be notified, so if there is a change in data from server-side would it automatically fetch the Data or we need to fetch the data and then as LiveData would change UI would change?

  11. Plot Twist: 1 Video Dislike = 10% chance of app crash for the Notes App Project.

    Note: I have a Notes App with dark mode (just implemented MaterialComponents plain theme and resulted in an App UI Wide dark mode change) and Same as this but Kotlin and How to implement SearchView to search notes?

  12. Hey man this video playlis is very cool I could understand it very well thanks for shareing your knowledge.


Please enter your comment!
Please enter your name here