Question Detail

Cannot access database on the main thread since it may potentially lock the UI for a long period of time.

2 years ago Views 2441 Visit Post Reply

While using Room Database in the Android app

If i add allowMainThreadQueries() in Room configuration all my listings are start hanging or lacking of scroll. SO i don't want to add it. My Project has almost 100+ Queries so i can add thread with every query to resolve it. Do you have any other idea or how can i make a different thread to reuse with all room query functions.

Android app example using Room database

java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
      at androidx.room.RoomDatabase.assertNotMainThread(RoomDatabase.java:267)
      at androidx.room.RoomDatabase.query(RoomDatabase.java:323)
      at androidx.room.util.DBUtil.query(DBUtil.java:83)


Thread Reply