Being Evil
Some developers do not like to take “no” for an answer. When they are told that they should not do database I/O on the main application thread — and that Room actively blocks that behavior — they get angry.
For those developers, there is allowMainThreadQueries()
.
This is a method on RoomDatabase.Builder
that you can call to turn off the ban on Room DAO calls on the main application thread:
private val db = Room.databaseBuilder(
myContext,
MiscDatabase::class.java,
DB_NAME
)
.allowMainThreadQueries()
.build()
Now, db
can be used on the main application thread, without complaints from Room. However, there might be complaints from users, or management, or the QA team, due to the app appearing to perform poorly.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.