Room basics – Introduction

Reading Time: 2 minutes

In this tutorial we are going to talk about how we can implement in our Android applications the Room persistent library. For this, we gonna create a whole new app. So, you can have a big picture about this library. In the introduction part we are going to summarize the tutorial.

Previously, if we wanted to store data locally on an Android device, we had to create manually the database helpers and the SQL queries. It took a long time and it wasn’t an easy task, because we could make many errors also, what what we got only at runtime.

Then Room come to the rescue. It was released in the Google I/O 2016. Room is one of Google’s architecture component library for working with SQLite on Android.

With the release of Version 2.1, the library added support for database transactions using coroutines.

Apps that handle non-trivial amounts of structured data can benefit greatly from persisting that data locally. The most common use case is to cache relevant pieces of data. That way, when the device cannot access the network, the user can still browse that content while they are offline. Any user-initiated content changes are then synced to the server after the device is back online.

By using annotations, we can create our database, tables and also the queries. The Room library will automatically translate these information and annotations into SQLite queries.

Room has three important components
    • Entity: It represents a table in the Room database, which should be annotated with the @Entity keyword.
    • DAO: It stands for Data Access Object, which is an interface, that contains the queries to access the database. It is annotated with @DAO
    • Database: It represents the database. Because it holds a connection to the SQLite database, all operations are executed through it. It is annotated with @Database.


Example application

In this tutorial, to show you how does Room works, we are going to create a whole new app. This application will contain a RecyclerView, a Floating Action Button and a DialogFragment, where we can create and modify the created items.

This application will be a ToDo list app. You can add a title and a description to your todo, and you can schedule it. Every todo item will have a priority as well, which can be low, medium or high.

If you aren’t familiar with RecyclerView, then check out our basic tutorial under the link

RecyclerView tutorial

In this sample application we are going to use some other Architecture Components as well, like

      • Coroutines
      • Data Binding
      • LiveData
      • Navigation Component
      • ViewModel


One more thing, the application will be uploaded to GitHub. Every chapter will have its own branch.

So it is also important to know how you can use GitHub and Git in Android Studio.

If you aren’t familiar with them, then check out our this tutorial also.

Share project on GitHub


      1. Introduction
      2. The starter project
      3. DAO, Database and Entity
      4. ViewModel


I hope the description was understandable and clear. But, if you have any questions, then leave me your comments below! 😉

Have a nice a day! 🙂



Follow and like us:
Click to rate this post!
[Total: 1 Average: 5]

4 thoughts on “Room basics – Introduction”

  1. I think that is among the so much important information for me.
    And i’m happy reading your article. However wanna remark on few common things, The web site style is
    wonderful, the articles is in point of fact excellent :
    D. Good job, cheers

  2. Howdy! Would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would really enjoy your content. Please let me know. Thank you

Leave a comment

stay informed!

Subscribe to receive exclusive content and notifications