Room Database , ViewModel , LiveData, RecyclerView (MVVM) || Android Architecture Component

In this tutorial you will learn the following.

  1. How to add room database dependencies.
  2. How to add livedata dependencies
  3. Insert and select data from room database
  4. Show roomdatabase data in a recyclerview.
  5. Android Modal View View Modal architecture.

Let’s get started.

Major Components in Room Database:

  1. Database: Main access point for the underlying connection to your app’s persistent relational data. Usually annotated with @Database.
    An abstract class that extends RoomDatabase.
    It contains an abstract class that has no arguments which returns class annotated with @Dao.
    It contains a list of entities.
  2. Entity: Represents tables in the database.
  3. Dao: It contains methods used to access the database.

LiveData is an observable data holder class, it’s lifecycle aware meaning only updates app component observers that are only in an active lifecycle state.

We use LiveData in view model because of the following benefits.

Use of observers to only update UI when data actually changes instead of polling for changes
No database calls from ViewModel.
ViewModel extends AndroidViewModel class

ViewModel takes care of holding processing data needed for UI.

For any additional question or personal assistance kindly comment below and i will get back to you.

Buy source code for $5