Exploring the vastness of the Realm, a cross-platform mobile database

What You’ll Need

Setting up

Create a new project in Android Studio called RealmNotes and choose a location for it. I usually store my Android apps in ~/Projects/Android/, but feel free to put it anywhere you like.

Getting our dependencies

Open up your project-level build.gradle and add the JitPack repository to it so that we can install libraries straight from GitHub. Then add a dependency for the Realm plugin:

User Interface

Open up app/res/layout/activity_main.xml and change the floating action button icon to have a “ ” instead of the default image:

Entering the Realm

We need to get our view to send information to our Activity, which will have all the knowledge of our database. But first we need to tell our application what we want to store.

Exploring the Realm

Bonus

Through the RealmBasedRecyclerViewAdapter we also get some nice bonuses out of the box. You’ve already seen one of them, which is the capability of auto-refreshing, but try and swipe one of your notes left or right, and you’ll see it gets deleted from the database. We enabled this earlier when we created our layout and set app:rrvSwipeToDelete to true.

You own the Realm

Now that we’ve looked at how to create a simple application using Realm as a database, how about moving on to a more complex application or using its true multi-platform strength across different applications?

--

--

Marcos Placona is a developer evangelist @ Twilio. He spends most of his time working with Android and .Net open source projects.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store