Access Android Room Database Version At Runtime

Apr 13, 2018

I believe there is no Room API to access the database version programatically.

But, you can use this trick.

Create a singleton object class (Kotlin) to store the database version.

object App {    const val DATABASE_VERSION = 1}

Specify the database version using the App singleton object.

@Database(entities = arrayOf(...), version = App.DATABASE_VERSION)@TypeConverters(...)abstract class AppDatabase : RoomDatabase() {    ...}

Now you can access the database version anywhere.

App.DATABASE_VERSION

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.