🔍 Exploring Android Room Database with Room Explorer

The in-app database viewer and manager for your Room databases.

The SQLite has been a big part of the Android ecosystem and is found in almost from every small size to large-scale app. It does indeed help in organizing data in the local storage and persistence to either help in reducing network calls or make content delivery fast.

The implementation of the SQLite wrappers in Android development has evolved from the SQLiteOpenHelper to the latest Annotation-based Jetpack Room database. In-between there were some big third-party solutions such as SQLiteAssetHelper, GreenDao, DBFlow (my favorite until Room) and numerous others.

💡 Idea & Inspiration

When developers add local database in their apps through any method, they find a little challenge in viewing the state of the database and the data its holding in the raw format. For this, you either need to debug the database manually at compile time, or use sort of bridge like Facebook Stetho. I like that personally and use it all my apps, but it relies on Chrome and I always wanted something which let me view database within the app.

With the goal of some in-app database viewer, I looked around internet and found this Android Database Manager by Sanath Kumar. This is a fantastic piece of code. And it does the job. I used it for my apps using SQLiteOpenHelper . But later I shifted to DBFlow, and I still wanted this to accompany me there too. So, I played with it and modified to work with DBFlow databases and created an open source library called as DBFlowManager from it. I have used it extensively in all my apps which uses DBFlow. Surprisingly, this library has been downloaded more than 10,000 times.

[DBFlowManager ](https://github.com/wajahatkarim3/DBFlowManager)statistics from Bintray

But when, Android launched its own annotation-based SQLite wrapper creatively called as Room , I switched to it. It’s a lot similar to DBFlow. But, now I had to again find the solution to viewing Room databases in the apps.

🥁 (drum roll) Presenting The Room Explorer

RoomExplorer is a slight modification of the DBFlowManager. It allows you to view your Room databases inside the app. I usually add a hidden trigger of Volume Down keypress to open the database in any screen at any time. You can view all tables and their rows, add/delete rows, edit the values, drop tables directly in the app. Here’s a simple GIF demo from the Readme page of RoomExplorer.

Room Explorer — Demo

You can see that on clicking the “Show Database” button, it opens another screen where you can see all your tables and the rows of your whole database.

😲 Wow! But How to Use This in My Apps?

The library is available on jCenter , so you just need to add this in your app’s build.gradle file first.

dependencies {
  implementation **'com.wajahatkarim3:roomexplorer:0.0.2'**

And now all you need to do is to call this one line where you want to trigger the RoomExplorer and view the database in the app.

RoomExplorer.show(context, MyRoomDB::class.java, "MyRoomDBName")

I do this in my BaseActivity class when the Volume Down key is pressed. Its like a secret trigger for me only available in debug builds. You can see that the show() method takes Context , your Room database class, and the name of your Room database.

⭐️ Check More Details of RoomExplorer & Show Some Love

You can find all the details about the RoomExplorer on its Github page here. Please don’t forget it a Github star and share it on social media. I would really appreciate that. 🙏

If you liked this article, you can read my new articles below:

profile card
Wajahat Karim
🌍 Making the world a better place, one app at a time.
🔥 Google Developer Expert (GDE) in Android . 📱 Professional Android Developer with ~10 years experience. 💻 Creator of various Open Source libraries on Android . 📝 Author of two technical books and 100+ articles on Android. 🎤 A passionate Public Speaker giving talks all over the world.
Author's picture

Wajahat Karim

🔥 Google Dev Expert (GDE) in Android .
📱 Android Dev. 💻 Open Source Contributor . 📝 Technical Writer . 🎤 Public Speaker

Senior Android Developer

Karachi, Pakistan