Realms of Chaos
I’ve been developing Android apps for few years now, and even if I’m a huge fan of what the platform offers to developers, one thing has always bothered me: Databases.
I come from the web world, where you have very powerful ORMs (like Hibernate, Entity Framework…). And when you arrive to Android, what you have is… SQLite. Hard to use, painful to work with… It’s such a mess that I’ve avoided it as much as possible. Then came ORMs for Android, like ORMLite, GreenDAO, ActiveAndroid…
I had the occasion to work with most of them, and even if some are better than others, globally, they’re really, really not efficient enough. At least in my opinion. Models generation, data migrations, APIs… Most of these things are hard to work with when it comes to Android ORMs.
Here comes Realm
Then came Realm. A promising database with a nice APIs and a SQLite-like performance (or even better). It’s actually a whole new DBMS, written in C++, and available on iOS (Swif/Objective C) and Android. Besides being really fast, Realm offers an API so nice it reminds me my good old Entity Framework.
They present their product better than me, so go visit heir website: http://realm.io
It’s pretty easy to setup, and you can start making your entities in a minute. And if you doubt about speed, know that not so long ago, your data manipulation and reading had to be done on the same thread. But from what I’ve experienced, it had no major performance impact (and Joaquim Verges, creator of Falcon Pro, has the same conclusion: https://realm.io/news/joaquim-verges-making-falcon-pro-3/). Don’t worry, if you still want to read data in a background thread and display them in the UI thread (which is probably a good idea, or an absolute requirement, depending on how you see things), Realm is now offering async methods for data manipulation!
Why is it so great?
Even if Realm has been around for several years, I haven’t tried it until recently (even if I was keeping an eye on it). After all, the Android version hasn’t reached the 1.0 version!
I’ve started to use it on Condor, a Twitter client app I’ve made last summer, and to be honest, I was impressed. Since then, I’ve used it on Astonishing Comic Reader, powering some very, very huge collections of books, without any problem. And I’m basically planning to add it to use it in all my future projects.
So it’s just the most perfect library in the world?
Actually not. It has some flaws. After all, it’s still in beta.
The brand new async methods seems not that stable, at least for now ( One of my colleagues had a severe bug which stucked him for a day or so). Some parts are also a bit tedious to use, like the Realm migration API. It’s changed recently, and it’s much better, but I feel like there’s still room for improvement. But anyway, I still consider it’s one of the best libraries you can find on Android.
What are you waiting for?
Seriously, go try it. Copy/paste the Gradle dependency line, and start to play with those RealmObject. I’m sure you’ll be quickly convinced!