A loan-application app is killed in the background while the user photographs their ID at step four, and they return to an empty step one. What went wrong, and what fixes it?
answer
- rotation is not the same test
- three things died with the process
- the route stack is state too
- choose the photo's file before the hand-off
- rebuild from identifiers, then validate
basics
~20 sThe draft, step and pending photo lived only in memory, so process death wiped them. Persist the draft on disk, keep its identifier, the route stack and the photo's target file in saved UI state, and rebuild from them.
solid answer
~50 sThree things died with the process: the draft held only in memory, the knowledge that the user was on step four, and the pending capture, because the screen waiting for the photo no longer exists. The fix makes each one survive. Write the draft to disk as the user edits. Keep the draft identifier and the route stack (home, application, step four) in small saved UI state. Before handing capture to another app, choose the photo's destination file and record it, so the recreated screen can find the photo whether or not a result is delivered to it. On relaunch the screen rebuilds from those identifiers, reloads the draft from disk, checks the photo file exists, and falls back to a valid screen if anything is missing. I would prove it by forcing a background kill during development, because rotating the device never exercises this path.
code
pseudocode · 13 lineson_screen_created(saved):
if saved is empty:
show(start_screen)
return
draft = load_draft_from_disk(saved.draft_id)
if draft is null:
show(application_summary) # draft gone: do not show a broken step
return
if saved.pending_photo_path is set and file_exists(saved.pending_photo_path):
draft.id_photo_path = saved.pending_photo_path
save_draft_to_disk(draft)
step = clamp(saved.step, 1, draft.last_reachable_step)
show_stack([home, application(draft.id), form_step(draft.id, step)])go deeper
Recall that the app can be killed while another app has the screen, and that only saved UI state and disk survive. Name where the draft should have been.
Walk the fix: draft on disk, identifiers and route stack in saved UI state, a photo destination chosen before the hand-off, and the rebuild path on relaunch.
Diagnose from the symptom, explain why rotation tests missed it, and add validation and fallbacks for restored state that no longer matches the data or the build.
Make survivable restoration a definition of done for every multi-step flow, and decide how the team proves it in development rather than in reviews.
## What the user saw, and why The user filled in personal details, income and employer, reached step four, and tapped **take photo of your ID**. When capture runs outside the app's process (a separate camera app or a system capture screen), the loan app sits in the **background** for the whole capture. Background processes are the first the OS reclaims when the device needs memory, and the OS ended the process without running any shutdown code. When the capture finished and the user returned, the OS started a **new process**. The app found nothing to restore, so it showed its start screen: an empty step one. This is **process death**, and it is one of the most common real-world defects in form-heavy apps, because it never appears during ordinary development: the developer's device has plenty of memory, and the usual robustness test, rotating the screen, keeps the process alive. ## Three things that died with the process | Lost state | Where it lived | Where it should live | |---|---|---| | The draft (details, income, employer) | An in-memory state holder | On disk, written as the user edits | | "User is on step four of draft 42" | Nowhere, or in memory | Small saved UI state: draft identifier, step, route stack | | The pending photo capture | A screen object waiting for a result | A destination file chosen before the hand-off, recorded with the draft or in saved UI state | ## The fix, step by step 1. **Persist the draft continuously.** Each field change updates the on-disk draft on a short debounce, and leaving the foreground flushes it. 2. **Save the route stack as small state.** The route stack is the ordered list of screens the user navigated through: home, the application, step four. Save it as identifiers (screen names, the draft identifier, the step index), not as screen objects. How much of the stack the OS recreates by itself differs: one platform rebuilds the screen stack and hands each screen its saved state; on the other, restoration is something the app opts into; cross-platform frameworks rebuild their own navigator from what the app saved. In every case, **the data comes back only if the app saved it**. 3. **Decide where the photo lands before handing off.** Generate a file path in the app's private storage, record it, then start the capture with that destination. When the process is recreated, the screen checks for the file. If a result is delivered to the recreated screen, it confirms the same path; if not, the file's presence is enough. 4. **Rebuild by reference.** On relaunch the screen reads the draft identifier and step, loads the draft from disk, attaches the photo if the file exists, and shows step four. 5. **Validate before restoring.** If the draft was deleted or the saved state names a step that no longer exists, route to a valid screen rather than a broken one. ## Validating restored state Saved UI state can outlive the code that wrote it. One platform's own guidance shows an app recording its version when it saves UI state and **refusing restoration** if the version does not match on relaunch. The general rule: treat restored identifiers as untrusted input, check the draft exists, check the step is valid for that draft, and fall back to the nearest valid screen, such as the application summary, when something does not line up. ## How to find this before users do - Force a background kill during development (developer settings or the debugger can terminate a backgrounded process) and return to the app, rather than only rotating the device. - Watch for reports of "the app forgot my progress" after the user used the camera, a password manager or another app. - Automating that check belongs to mobile test design; the design's job is to make the path exist. ## Neighbouring concerns Memory pressure is what makes the kill likely, and that budget is its own topic; this question is about what the kill costs and how state returns. Building a route stack from an incoming link is navigation's job; restoring the stack the user already had after process death is the lifecycle's. Choosing the on-disk store for the draft, and protecting an identity document at rest, are their own design decisions.
- Why does the bug never show up when the developer rotates the device?Rotation is a system-driven UI rebuild: the process stays alive, so an in-memory state holder hands its state to the rebuilt views. Process death destroys the whole process, and only saved UI state and disk remain. A form that survives rotation has only proved it survives a rebuild. The test has to kill the backgrounded process and then return.
- What should the app do if the saved state was written by an older build?Treat it as untrusted. Record the app version alongside the saved UI state and decline to restore if it does not match, as one platform's own guidance illustrates, or validate each identifier and fall back to a valid screen. The draft on disk is still the user's work, so the app offers it even when the exact screen cannot be restored.
- Rotating the phone in testing proves the form survives process death.
- The OS rebuilds step four with all its data, so nothing needs saving.
- Saving the draft in the screen's teardown handler is enough.
- Keep the captured photo in memory until the user taps submit.
- Restore saved state blindly without checking the draft still exists.