DictionaryActivity used DatabaseService.withRealm { ... }, which opens the Realm database on whatever thread calls it — no background dispatch. Three things were running database work directly on the UI thread:
- The search button. Every time the user tapped "Search," it ran a case-insensitive query across the entire dictionary (equalTo("word", ..., Case.INSENSITIVE).findFirst()) on the main thread. On a large dictionary that scan can take long enough to freeze the UI or trigger an "App Not Responding" dialog.
- The initial count() check in loadDictionaryIfNeeded() also ran on the main thread (it was inside a Main-dispatched coroutine).
- The search listener (setClickListener) was only being attached when the dictionary was already populated. On the very first launch right after the data got inserted search wasn't wired up at all, so it silently did nothing until the user closed and reopened the app.
DictionaryActivity used DatabaseService.withRealm { ... }, which opens the Realm database on whatever thread calls it — no background dispatch. Three things were running database work directly on the UI thread: