🔍 Exploring Android Room Database with Room Explorer

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

Originally published at https://wajahatkarim.com.

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 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. 🙏

To receive more tips and articles about Android development, join my email list DroidUp.

Wajahat Karim is a graduate from NUST, Islamabad, an experienced mobile developer, an active open source contributor, and co-author of two books Learning Android Intents and Mastering Android Game Development with Unity. In his spare time, he likes to spend time with his family, do experiments on coding, loves to write about lots of things (mostly on blog and medium) and is passionate contributor to open source. In June 2018, one of his library became #1 on Github Trending. His libraries have about 2000 stars on Github and are being used in various apps by the developers all around the globe. Follow him on Twitter and Medium to get more updates about his work in Writing, Android and Open Source.

Also, if you have any questions you’d like him to answer, contact him through his website at wajahatkarim.com with DEAR WAJAHAT in the subject line.

Originally published at https://wajahatkarim.com.

🔥 Google Dev Expert (GDE) in Android . 📱 Android Dev . 💻FOSS Contributor . 📝Writer . 🎤 Speaker . 👶 Developer Dad — 🌐Subscribe at https://wajahatkarim.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store