Realm VS Room in Android

AndroidRealmAndroid Room

Android Problem Overview


I'm building an app and I need to use a database in it. I'm considering using Room as it's new and hot right now. But I've heard a lot of great stuff about Realm too. Can someone point out the possible advantages of using each?

I did my research and read the docs but I have no experience to understand it myself

Room docs

Realm docs

EDIT:

It's been some time and and I can point out another reason to use Room. Although you can use Realm and Transformations to tie things up with LiveData but with Room you can directly return LiveData (and also RXJava types using a plugin) for the DB, which will save you some boilerplate code and headache.

EDIT 2:

In addition to the first edit, Room now has a first class support for coroutines in Kotlin so if you are planning to use those it will be a nice-have -> https://medium.com/androiddevelopers/room-coroutines-422b786dc4c5

Android Solutions


Solution 1 - Android

Realm

A relatively fast and convenient library, all links are simply implemented, which is related to the object orientation of the database. Excellent documentation. Is, perhaps, one of the best option for storing data on a mobile device at the moment, the minus can only be an increase in the size of the apk-file by 2.5 MB.

Room

An interesting solution presented on Google I / O 2017 as optimal for working with the database on Android OS. Despite the fact that it is necessary to use explicit sql-requests, the library turned out to be quite convenient and I liked it personally. On performance is in the lead, so I would advise you to choose this particular library. Big advantage of this is based on build-in SQLite database. Since this solution, submitted by Google, it will quickly become popular, and, therefore, there will be no problems with finding solutions to problems that occur along with it.

Realm uses more RAM and increases the apk size, build time. So I prefer Room.

There are comparison: https://github.com/AlexeyZatsepin/Android-ORM-benchmark

Solution 2 - Android

The main reason that we pushed to use a library for database is the fact that it let us model our objects and made CRUD easier, I had a good experience with Realm, it's really easy to set up and work, it's fast and flexible, but size of the library was an issue, it's possible to reduce APK size by splitting APKs on build target ABI but I preferred to use GreenDao because it's based on SQLite, although I think it has some disadvantages like any other libraries but it was the best option for me.

Honestly, I didn't try Room yet but with a brief look at the documents you will find it more flexible and friendly to developers, As a Google fan, I prefer to use Google guys' library! As I said before I prefer a layer over native SQLite to a whole new database library.

I will try Room in my next project and share my experience here in an update later, hope it helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRainmakerView Question on Stackoverflow
Solution 1 - AndroidAlexey ZatsepinView Answer on Stackoverflow
Solution 2 - AndroidFarshad TahmasbiView Answer on Stackoverflow