DEV Community

Cover image for The Startup Crashes Your Kill Switch Never Sees

The Startup Crashes Your Kill Switch Never Sees

Prikshit on November 23, 2026

A Room migration or a missing R8 keep rule can put an Android app in a crash loop before Remote Config loads. A flag can't reach that code, so test...
Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

The Kotatsu 24-to-23 example is the whole piece in one bug. Downgrade with no migration path leaves only the destructive one.

Collapse
 
prikshit profile image
Prikshit • • Edited

Right, and the trap is that a plain revert looks correct in code review. One cheap guard is a CI check that reads the exported schema folder and fails the build if the @Database version is lower than the highest schema JSON already committed, because a shipped version number should never go backwards. That forces the rollback build to carry the newer schema or a forward migration, so the user keeps their rows.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

A revert that looks correct in review is the dangerous kind. The CI check turns it into a build failure instead of a shipped bug.

Thread Thread
 
prikshit profile image
Prikshit •

Yes. The check only stops the next bad revert from shipping. Anyone who already opened the v24 database still needs a forward migration or a startup guard that can open in safe mode without touching the database. The CI job and the kill switch cover different moments, and you need both.

Thread Thread
 
robertpaschal profile image
Odinaka Robert Nnamani •

Right, the check only guards the next deploy. The ones already on v24 need the forward migration or the safe-mode guard, not another CI gate.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

That CI check is a good guard. Failing the build when the version drops below the highest committed schema catches the revert before it ships.

Collapse
 
userxnom profile image
Abdullah Naseer •

The Kotatsu example is the one that will stick with me — a database sitting at version 24 with code expecting 23, and the only escape being a destructive migration that wipes the user's data. The startup guard is the practical takeaway for me: counting REASON_CRASH through getHistoricalProcessExitReasons and opening in safe mode with the database closed after two failed launches feels like something every app with a Room migration should have. One question on the guard's blind spot: you note crashes in Application.onCreate or a content provider never reach the counter — have you found a practical way to cover that window, or is counting in attachBaseContext the only honest answer and just not worth the background-process noise?

Collapse
 
prikshit profile image
Prikshit •

Good question. Counting launches in attachBaseContext() is noisy, but reading crashes there isn't. ApplicationExitInfo records a crash in Application.onCreate() or a provider like any other, so on Android 11 and later attachBaseContext() can call getHistoricalProcessExitReasons(), keep the REASON_CRASH entries for its own process name that are newer than the last completed launch, and set a safe mode flag without writing anything. A background start then only pays for that one lookup. The harder part is acting on the flag. Your own init in onCreate() can check it, but an App Startup initializer runs before onCreate(), so it only becomes skippable if you remove it from the manifest and call AppInitializer yourself behind the same check. On Android 15, ApplicationStartInfo also reports why the process started, which could separate launcher starts from push or job starts, though it's worth checking how early that record is filled in before relying on it.