A user has written a careful problem report, chosen a category, and attached a photo. Then the operating system ends the app process—or the device restarts.
When the user opens the app again, what should happen?
It depends on what each piece of information represents. A selected tab and an unsent report are both state, but they have different owners, lifetimes, and recovery requirements. Treating them alike can either lose meaningful work or lead to elaborate persistence for details nobody expects to survive.
Start with the interrupted workflow
Imagine a report form with these fields:
- Title and description
- Selected category
- A photo attachment
- Whether the keyboard is open and which field has focus
- A save or upload status
The title, description, category, and attachment are work the user created. They should survive an interruption. Keyboard visibility and focus are presentation details; restoring them may be useful, but they should not be necessary to recover the report.
The upload status needs special care. “Uploading…” describes an operation that was in progress; it does not mean that operation can resume after the process ends. On relaunch, reconcile with the actual upload state rather than blindly restoring that label.
For each value, ask: If this disappears, does the user have to recreate meaningful work? If yes, give it a durable owner. If no, it may belong in lightweight UI restoration—or it may be fine to start fresh.
Give each kind of state the right owner
A form widget, view controller, or view model is a convenient place to hold state while a screen is alive. It is not, by itself, a durable place to keep user work. In-memory objects disappear with the process.
For the report, the durable owner might be a local database or a draft repository backed by one. The form reads from and writes to that owner. The screen can be rebuilt; the draft remains.
| State | Reasonable owner | Expected lifetime |
|---|---|---|
| Draft text and selected category | Local draft store | Until submitted or explicitly discarded |
| Photo attachment | App-managed file, referenced by the draft | Until no longer needed |
| Current tab or expanded section | UI restoration state | Often until the app or scene is restored |
| Keyboard visibility | Live UI state | Usually not worth persisting |
| Upload progress | Upload service plus server reconciliation | Only while the operation is actually in progress |
This is more useful than a blanket rule to “save everything.” Durable storage adds work: migrations, cleanup, privacy decisions, and conflict handling. Persist information when losing it would matter; keep transient presentation details transient unless restoring them clearly improves the experience.
Save the draft before the lifecycle gets interesting
A common mistake is to wait for a background or termination callback and save the whole form there. Lifecycle callbacks are useful signals, but they are not a dependable last chance to write. The system can end a process without giving the app time to complete arbitrary work.
Persist meaningful edits during the editing flow, not only when the user leaves the screen. A short debounce can reduce writes on every keystroke, but it creates a window in which the latest edit may not be saved. Choose that tradeoff deliberately, and don’t rely on a termination callback to flush pending writes. If the product promises that edits are saved, make sure the persistence operation has completed before presenting them as safely saved.
For attachments, copy the selected file into storage the app controls and persist a reference to that copy. A picker-provided location may not remain accessible indefinitely. Keep the file and its draft reference consistent: a restored draft should not point to an attachment that was never successfully copied or has since been deleted.
Give each draft a stable identifier and enough metadata to make restoration a decision rather than a guess. For example, store creation and update times, a schema version, and—if the draft is based on server data—the server version it came from. Use transactions or atomic-write facilities where appropriate so an interruption does not leave a half-updated draft.
Restore work, not a frozen screen
On launch, make restoration an explicit flow:
- Find the relevant unfinished draft.
- Check that its stored version can be read and that referenced files exist.
- Load the draft into the form.
- Recalculate derived presentation state, such as validation messages.
- Reconcile operations that may have changed while the app was away.
That last step matters. If the report was submitted just before the process ended, showing the old draft as unsent could invite a duplicate submission. When the backend supports it, give submissions an idempotency key or another stable operation identifier, and check the current server state before retrying an uncertain operation. If a draft was based on a record that has since changed elsewhere, surface the conflict or apply a defined merge policy; don’t silently overwrite newer data.
Decide what happens to stale drafts. Keep them until the user submits or discards them? Offer to resume or delete them after a period? The right policy depends on the form’s purpose and sensitivity. Whatever you choose, make it predictable; avoid silently deleting work just because a timestamp crossed an arbitrary boundary.
Platform mechanisms are not interchangeable
Each platform offers ways to recover some state after an interruption. These mechanisms can help, but none should be mistaken for a durable draft store.
Flutter
Flutter’s restoration framework can restore supported, serializable widget and navigation state when restoration is configured. It can be useful for lightweight interface details: which route was open, a selected page, or a small value needed to rebuild a screen. Restoration properties and IDs help the framework connect saved values to the rebuilt widget tree.
They are not a replacement for saving a report. Put draft content and attachment references in a repository backed by durable local storage. On restoration, use UI restoration data to reopen the right workflow, then load the actual draft from that repository. A route identifier can say “resume report editing”; it should not be the only copy of the report.
Android
Android’s saved instance state is intended for small amounts of state needed to recreate an activity or UI after configuration changes or system-managed process death. A ViewModel helps retain state across configuration changes, but an ordinary in-memory ViewModel does not survive process death. SavedStateHandle can help recover small values associated with a ViewModel; it is not a store for substantial or durable user content.
Keep the report in a persistent data layer, such as a database, and let the recreated screen load it. Use saved instance state or SavedStateHandle for compact restoration details—such as a draft ID or current step—not the complete report and its attachment bytes.
iOS
SwiftUI’s @State and @StateObject support view and model state while the relevant process is alive; they should not be treated as durable storage. @SceneStorage and UIKit’s state restoration facilities can help restore lightweight, scene-specific interface state, depending on how the app is structured and configured.
Save important draft content to durable storage independently of scene restoration. When a scene returns, use its restoration information to find the right screen or draft, then reload the authoritative draft. System restoration helps rebuild context; it does not guarantee that arbitrary in-memory data will be preserved.
Across platforms, the division is the same: restoration remembers enough context to reopen the workflow; the app’s persistence layer remembers the work.
Test the interruption, not just the rebuild
A rotation test or view reconstruction test can catch useful bugs, but it does not prove that a draft survives process death. Test the boundary the user cares about:
- Enter a title and description, choose a category, and attach a photo.
- End the app process without completing the report.
- Relaunch and verify that the draft and attachment are usable.
- Change the draft, interrupt again, and verify that the latest saved edit returns.
- Remove or invalidate an attachment reference and check that recovery fails gracefully.
- Interrupt submission when the server may have accepted it, then verify that the app does not create a duplicate report.
- Open the same draft after its underlying server record changes and verify the conflict behavior.
Test the storage layer separately for failed or interrupted writes, schema upgrades, and draft cleanup. Then test the full user path with process termination and relaunch on each platform. Backgrounding an app is not the same as destroying its process, and rebuilding a screen in a test is not the same as recovering it after the process is gone.
The goal is not to make every pixel reappear exactly as it was. Preserve the user’s meaningful work, restore enough context to continue, and avoid pretending an interrupted operation completed when it may not have. With clear owners for each kind of state, app restarts become a recovery path—not a gamble.
Top comments (1)
The line that stuck with me is "restore work, not a frozen screen" — it's a cleaner way to think about it than trying to make every pixel reappear. My app is offline-first with a local database, so the draft-persistence part maps directly: the report lives in the database, and the screen just reloads it. The test checklist at the end is the part I needed most — interrupting a submission and checking for duplicates is a test I haven't written, and it's exactly the kind of bug a driver would hit on a bad connection.