How to Copy Realm Objects to Room Database using Android Studio

in #utopian-io6 years ago (edited)

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

Sort:  

I thank you for your contribution. Here are my thoughts;

  • There was a lot of background noises including keystrokes and some of your sentences were unclear / incomprehensible. To solve it, you can change your microphone settings and practice before talking.

  • What you've shown in the video tutorial is rather practical than theoretical. Every person with little programming skill and database knowledge can find own way in these situations. A tutorial should encourage users to find their way, shouldn't show or force them the way.


Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Well thanks @yokunjon for moderating but,

A tutorial should encourage users to find their way, shouldn't show or force them the way.

I really don't understand what you meant by that.
The tutorial is to show the users how to accomplish a certain task with best Android practices.

I thank you for the feedback. Briefly, what you've done is showing how you solve the problem. Actually, it's a basic engineering problem. In these situations, the real learning happens when the user solves it by himself. So, the content of your tutorial isn't a good example as a tutorial. You've already shown them how to create Realms databases, so let them find their own way and migrate their databases to another one when needed. Because, if you were to show the same thing for each database, it would be lots of content which repeats itself.

A real world example would be teaching how to step each step rather than generally walking.

If you need more detailed/further explanation, that is not problem, don't hesitate to ask. :)

Chic article. I learned a lot of interesting and cognitive. I'm screwed up with you, I'll be glad to reciprocal subscription))

Hey @edetebenezer
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!