health: move food/reference catalog init off the main thread
- Commit
cb8ee3b7ba29fd602ecbf53feb810b571887d122- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-05 18:26 UTC (9 hours ago)
- Parents
5b18ae5
onCreateBeforeContent ran FoodDatabase.init and ReferenceCatalog.init synchronously on the main thread: SQLCipher native load, scratch-file deletes and unpacked-meta file reads before setContent. No first-frame screen needs either catalog (Today renders from Room/Health Connect; the catalogs serve only food/medication pickers), so both inits plus the existing half-second warmUp unpack now run in one Dispatchers.IO block. Health Connect setup, which the Content gate reads, stays synchronous. Verified: :health:lint :health:lintVitalRelease :health:testDevUnitTest pass.
Diff
health/src/main/java/com/vayunmathur/health/MainActivity.kt
diff --git a/health/src/main/java/com/vayunmathur/health/MainActivity.kt b/health/src/main/java/com/vayunmathur/health/MainActivity.ktindex 82bfd769e8..dd99ccc049 100644--- a/health/src/main/java/com/vayunmathur/health/MainActivity.kt+++ b/health/src/main/java/com/vayunmathur/health/MainActivity.kt@@ -14,6 +14,8 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.lifecycleScope+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launch import com.vayunmathur.health.data.FoodDatabase import com.vayunmathur.health.data.HealthAPI import com.vayunmathur.health.data.HealthRepository@@ -72,11 +74,17 @@ class MainActivity : MaActivity() { // Room, the food database and the reference catalog work without it, and the composable // below shows the install screen instead of the app until it is usable. ensureHealthConnect()- FoodDatabase.init(this)- ReferenceCatalog.init(this)- // Unpacking is half a second of decompression and disk write. Do it now, in the background,- // rather than the first time the user opens a picker and waits for it.- ReferenceCatalog.warmUp(lifecycleScope)+ // Food/reference catalog init is disk work (SQLCipher native load,+ // scratch-file deletes, unpacked-meta reads) that no first-frame+ // screen needs: the Today page renders from Room/Health Connect,+ // and the catalogs only serve food/medication pickers. Keep it off+ // the main thread; warmUp's half-second unpack follows in the+ // same background block rather than at the first picker open.+ lifecycleScope.launch(Dispatchers.IO) {+ FoodDatabase.init(this@MainActivity)+ ReferenceCatalog.init(this@MainActivity)+ ReferenceCatalog.warmUp(lifecycleScope)+ } } @Composable