Choosing Database For Android App: Realm

image source: https://realm.io/

If you want to make a fast and reliable Android application, it’s important to think about every aspect of development. At this point, one of the first things you will need to figure out is how to exactly store and search for big amounts of data. Normally, developers would use SQLite for this purpose. However, there is an alternative to the traditional Android database. It’s called “Realm”. In this article, we are going to dwell on the Realm advantages and explain why we consider it a good choice.

SQLite

SQLite is an open-source database that comes integrated in the latest Android versions by default. For interaction with the OS, SQLite uses the SQLiteDatabase and the SQLiteOpenHelper Java interfaces. The programming interface is fairly simple and user-friendly since it is written in pure ANSI-C. In terms of size, SQLite is relatively portable: you can store the whole database in one disk file. At the same time, implementing standard mechanisms to manage SQLite is hardly a trivial procedure as you need to manually write tons of code. Because of that, developers have to use various libraries and ORM add-ons.

Realm

The alternative to SQLite is Realm. Being a full-fledged cross-platform mobile database, Realm was created to become an ultimate solution for storing data both performance and efficiency-wise. What really sets it apart is that you can handle all the work with a couple of lines of code. Realm is very easy to install and more responsive compared to SQLite its ORM alternatives like ORMLite or Greendao.

Realm pros

  • As mentioned, one of the main reasons to choose Realm is the speed. Basically, it is 100 times faster than its ORM alternatives and 10 times faster than SQLite.
  • The ease of integration and the ease of use. Realm comes with great documentation and requires almost no effort to get started.
  • It is a trusted product. Realm has proven itself as a reliable solution for banking and enterprise applications, healthcare providers and even top rated applications like Starbucks.
  • It is fully open-source which means no fee or paid subscription required.

Though, we included Realm into our stack of technologies not only because of the mentioned features but also due to its remarkable versatility that enables cross-platform development. From our experience, the biggest advantage of using a single technology across different platforms is that it allows for better communication between several teams, and therefore simplifies both the development process and application maintenance.

From something in mind to something in kind

We have used Realm in many projects. For example, recently we have developed MoveShanghai — a fitness application for China allowing users to plan and access their fitness activities from any platform. Every page in the app is made to request data from the server. After it’s received, Realm comes into play. It caches the data and then selects the necessary one to sort and show it on the screen. Realm’s powerful engine allows for such manipulations without having to slow down the user interface. We also leveraged Realm’s speed to implement the search and the map display functionality. When typing the first letters of a word or a phrase MoveShanghai instantaneously gives the list of auto-suggestions. Finally, the app received a map to display large numbers of objects. This piece of functionality was implemented using Realm Android API and its realm-mapview tool for objects clustering.

Conclusion

The Realm database is a good choice if you need really fast and easy to use solution for storing and processing data in a mobile application. Implementing a database now takes a lot less time than it used to with SQLite. Of course, some aspects could be improved but it’s a different story.