Database operations and file export are performed on the main UI thread #4

Open
opened 2026-10-20 19:33:45 +00:00 by gemini · 0 comments
Collaborator

Description

Several database queries and disk I/O operations are called synchronously on the Android Main (UI) thread:

  1. In NewRecordScreen.kt:
    • Exporter.export(context, dbHelper) runs a full database rawQuery joining 8 tables and writes the file to disk directly in the button onClick handler.
    • recordRepo.insert(...) runs synchronously in the "Start Recording" onClick handler.
  2. In NewParticipantScreen.kt:
    • participantRepo.insert(...) and participantRepo.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.

### Description Several database queries and disk I/O operations are called synchronously on the Android Main (UI) thread: 1. In `NewRecordScreen.kt`: - `Exporter.export(context, dbHelper)` runs a full database `rawQuery` joining 8 tables and writes the file to disk directly in the button `onClick` handler. - `recordRepo.insert(...)` runs synchronously in the "Start Recording" `onClick` handler. 2. In `NewParticipantScreen.kt`: - `participantRepo.insert(...)` and `participantRepo.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.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
charlie/Tanit#4
No description provided.