Android and mobile engineer writing about shipping AI-assisted Android and iOS code: release gates, maintainability, and the decisions that still need a human.
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.
Android and mobile engineer writing about shipping AI-assisted Android and iOS code: release gates, maintainability, and the decisions that still need a human.
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.
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?
Android and mobile engineer writing about shipping AI-assisted Android and iOS code: release gates, maintainability, and the decisions that still need a human.
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.
We're a place where coders share, stay up-to-date and grow their careers.
The Kotatsu 24-to-23 example is the whole piece in one bug. Downgrade with no migration path leaves only the destructive one.
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
@Databaseversion 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.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.
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.
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.
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.
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?
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.