SQLite Browser in Android Studio

(available from Android Studio 4.1)

Table of Contents

What was it like before?

Before Android Studio 4.1 you had to rely on external programs (like “DB Browser for SQLite”) to read the data from a SQLite database. To do this, you first had to copy the database file from the emulator or real device to your own computer. I mostly used the integrated explorer for this. Also the .db-wal files had to be copied, because otherwise you didn’t have the last operations on the database.

File Explorer tool window
File Explorer tool window

How does it work now?

Since version 4.1, a viewer (Database Inspector) for SQLite databases is directly integrated in Android Studio. With this it is now possible to view the database of an app directly in Android Studio, to observe it or to change data (see also “Debug your database with the Database Inspector” guide on Android developer pages).

The viewer can only be used with emulators / devices from API 26 and up. And it only works when used with the built-in SQLite library. So only with libraries that use the included SQLite library and don’t bring one themselves.
Currently, there are problems with emulators with API 30 (Android 11) and Database Inspector. The apps crash in the process.

What is possible?

If the connection to the database is possible and established, the changes to the database can be followed live (see also video below). The changes in the tables are displayed directly, if the hook ‘Live updates’ is activated for them. Manual updating of the view is of course also supported.

If the Jetpack library Room is used as ORM, the queries from the DAO can also be executed directly (see video). The parameters for parameterized queries are queried in a friendly manner.

What are the benefits?

With the Inspector, programming can now be done much faster. Since you can see the changes immediately for the running app, you can analyze the bugs faster, or even let the new queries on existing app data be tried out easier.

Also very helpful at this point is that the emulator can be placed in a tool window instead of floating next to Android Studio. This gives you much more space during development and allows you to show the emulator whenever it is needed.

Conclusion

It is a long overdue feature in Android Studio. The “Database Inspector” makes the development of apps that use SQLite much more convenient and faster. Especially the live mode can be helpful in troubleshooting, as you can observe the data changes directly in the database.

comments powered by Disqus

Related