Pick the fix
The app freezes briefly on a list screen that calls a DAO function from the main thread with allowMainThreadQueries(). Best fix?
Hint 1 of 1
Which thread runs the query today?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Make the DAO function suspend or return a Flow, and remove allowMainThreadQueries
Correct. Room then runs the query off the main thread.
Why not the others?
- B Wrap the call in
runBlocking(Dispatchers.IO). Still blocks the main thread while it waits. - C Add an index to every column. Indexes may help speed, but the query still runs on main.
- D Use raw SQLite instead. Same problem, more code.