Skip to content

main-thread blocking problem (an ANR/freeze risk) #13912

@Okuro3499

Description

@Okuro3499

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:

  1. 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.
  2. The initial count() check in loadDictionaryIfNeeded() also ran on the main thread (it was inside a Main-dispatched coroutine).
  3. 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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions