How to Copy Realm Objects to Room Database using Android Studio

realmDark.jpg

Repository

https://github.com/realm/realm-java

What Will I Learn?

  • You will learn how to copy Realm Database Content to Room Database.
  • You will learn how to use Realm Queries.
  • How to use butterknife to inject views.
  • How to use Lombok library to reduce boilerplate codes.

Requirements

System Requirements

  • An Integrated Development Environment(IDE) for building Android Application(e.g Android Studio, IntelliJ)
  • Android Device/Virtual Device.

Required Knowledge

  • Little Experience in working with Realm Java.
  • Java Programming Experience.
  • Little or no Experience working with Room
  • Of course, willingness to learn

Resources

Difficulty

  • Intermediate

Tutorial Content

In today's tutorial, we are going to be learning how to copy our realm database objects and then save it in Room Database.

We develop an Android application that displays a list of Objects on the MainActivity layout file and when the user clicks a button, the objects are copied and stored in the Room Database and then displayed on the other textview.

The user is expected to click on the Database copy button to initialize the copying of the realm objects to the Room Database and also displaying the copy objects.

The source code of this tutorial can be found here

Time Frame

  • Application Sample - 00:00 - 00:47
  • Dependencies Used - 01:10 - 02:46
  • Setting up Room Database - 02:50 - 09:40
  • Setting up our MainActivity Layout file - 09:44 - 11:49
  • Linking Everything together - 11:52 - 23:47

Overview

  • Application Sample: This part of this tutorial shows the sample application that we intend to build.
  • Dependencies Used: In this part the used dependencies in the tutorial are being shown here, dependencies such as - butterknife (Used for view injection) , Lombok library (Used for reduction of Boiler plate code), Room(Used for creating and accessing sqlite database), Realm(Used for storing realm objects).
  • Setting up Room Database - This part of the tutorial we setup the three components of the Room Database (Entity, Database Access Object (DAO), Database object).
  • Setting up our MainActivity layout file (activity_main.xml) : This part of the tutroial, we set up the main activity layout file where we add Two TextVIews and a Button to our activitymain.xml file inwhich the two textviews will be used to display the details of the Realm and Room Database contents.
  • Linking Everything Together - In this part, we link all the earlier created components of the Application, and then we finally do the copying of the realm database content to the room database.

Video Tutorial

Proof of Work

https://github.com/generalkolo/Realm-Examples/tree/master/RealmToRoom

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center