Database operations and file export are performed on the main UI thread #4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
Several database queries and disk I/O operations are called synchronously on the Android Main (UI) thread:
NewRecordScreen.kt:Exporter.export(context, dbHelper)runs a full databaserawQueryjoining 8 tables and writes the file to disk directly in the buttononClickhandler.recordRepo.insert(...)runs synchronously in the "Start Recording"onClickhandler.NewParticipantScreen.kt:participantRepo.insert(...)andparticipantRepo.updateRecordWaves(...)execute on the Main thread.Impact
As the dataset grows (more records, participants, cities, dialects), executing heavy disk and SQLite operations on the UI thread will cause dropped frames, UI jank, or ANR (Application Not Responding) dialogues.
Suggested Fix
Wrap all database and export operations in coroutines using
withContext(Dispatchers.IO)and provide visual loading feedback (disable button / show indicator) while the operation is in flight.