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
Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite. In the case of SQLite, There is no compile-time verification of raw SQLite queries. But in Room, there is SQL validation at compile time.
Room is a Database Object Mapping library that makes it easy to access database on Android applications. Rather than hiding the details of SQLite, Room tries to embrace them by providing convenient APIs to query the database and also verify such queries at compile time.
What is Realm? Realm is an object database that is simple to embed in your mobile app. Realm is a developer-friendly alternative to mobile databases such as SQLite and CoreData. Before we start, create an Android application.
A new finder window will open, where you find your Realm inside in the following path (e.g.): AppData/Documents/default. realm (The path is /private/var/mobile , which is used by iOS on the device filesystem.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With