skip to content

App Lifecycle & Restoration

Foreground, background, suspended and terminated states, and the process death that wipes memory without warning. Interviewers ask what state survives, where it is saved and how work resumes.

on this pageshow

questions

5

In a mobile app's design, what do the foreground, background, suspended and terminated states mean, and what can the app rely on in each?

level: juniorimportance: must knowfreq 58%

answer

  1. attention decides priority
  2. off screen, finish up, go quiet
  3. in memory but not running
  4. no process, only disk remains
  5. the kill sends no notice

basics

~20 s

Foreground: visible and interactive, with priority on CPU and memory. Background: off screen, briefly running, expected to save and go quiet. Suspended: in memory but not running, killable without notice. Terminated: no process; only saved UI state and disk remain.

solid answer

~50 s

I treat the four states as shrinking promises. In the **foreground** the app is visible and has the user's attention, so it gets priority over CPU and memory. In the **background** it is off screen; it may run briefly, but it should finish crucial work, save what matters and go quiet, and longer work needs an OS-sanctioned background mechanism. **Suspended** means the process is still in memory but gets little or no CPU time, and the OS may end it at any moment without running any shutdown code. **Terminated** means there is no process at all: memory is gone, and the next open rebuilds the app from whatever was written to small saved UI state or to disk. So in a loan-application form the rule is: save before and while leaving the foreground, never in a 'we are being killed' moment, because that moment does not reliably exist.

go deeper

for a junior

Name the four states by what they mean: visible or not, running or not, kept in memory or not. Then say why the app must save before leaving the foreground.

for a middle

Explain that suspended processes are killed without notice and that teardown code is not guaranteed, so the save point is the move to the background, backed by continuous saving.

for a senior

Show the states as design constraints: which promises in the product depend on each, what an OS kill costs versus a crash or a swipe-away, and how the restore path differs.

for a principal

Set the team-wide rule that memory is a cache and every screen must come back from saved UI state and disk, and decide how that rule is enforced in review and testing.

## Why the states are a design constraint An installed mobile app does not decide when it runs. The **operating system** moves it between states based on what the user is looking at and how much memory and battery the device has left. In a design round, the interviewer is not asking for the names of callbacks; they are asking whether the design knows **what it can still rely on** in each state, because every promise the app makes to the user ("your form is safe", "your application was sent") has to hold across those transitions. Take the scenario of a **loan-application app**: a five-step form (personal details, income, employer, a photo of an ID document, review and submit). A user typing their income may switch to a banking app to check a figure, take a call, or leave the phone on the table for an hour. Each of those moves the app into a different state. ## The four states | State | Visible? | Code runs? | Memory kept? | What the design should assume | |---|---|---|---|---| | **Foreground** | Yes, with the user's attention | Yes, with priority | Yes | Normal work; keep the UI responsive | | **Background** | No | Briefly | Yes, for now | Finish crucial work, save, release what you can, go quiet | | **Suspended** | No | Little or none | Yes, until reclaimed | The process can be ended at any time with no further code running | | **Terminated** | No | No process exists | No | Only what was written to saved UI state or disk survives | A few clarifications that keep the table honest: - **Foreground** is sometimes split into a short visible-but-not-interactive moment (a system dialog or the app switcher covering the app) and the fully interactive state. Both native platforms have such a moment; the design treats it as "pause what needs the user's attention", not as a save point to rely on. - **Background** time is short and owned by the OS. Work that must run longer, such as a large upload or a scheduled sync, goes through the OS's own background mechanisms, whose budgets are a separate design topic. - **Suspended** is one platform's word; the other describes the same idea as a **cached** process that is kept around for fast switching, gets little or no execution time, and is the first thing reclaimed when memory is needed. The behaviour that matters is shared: the process sits in memory without running and can be removed without notice. - **Terminated** covers several causes: the OS reclaiming memory, a crash, a reboot, an app update, or the user deliberately swiping the app away. The first ones are invisible to the user; the last one is not, and that difference shapes what the app should restore. ## What each state means for the loan form - In the **foreground**, the user is filling step two. Edits go into an in-memory state holder for responsiveness and are written to the on-disk draft as they happen (debounced), so the disk copy is never far behind. - When the user leaves for the banking app, the form goes to the **background**. This is the last point the app is reliably told that it is losing the screen, so it flushes any unsaved edit and records which step and draft the user was on. - Minutes later the app may be **suspended**. Nothing runs. Any timer that was counting down a quote's validity stops; any request the app started on its own (not through an OS-owned transfer) is not guaranteed to finish. - If the device needs memory, the app is **terminated** silently. When the user returns, the OS starts a new process, and the screen must come back from saved UI state and the disk draft alone. ## The rule that falls out 1. **Save before the kill, never during it.** Neither native platform guarantees that any teardown code runs when it reclaims a background process; a crash skips it too. 2. **Save continuously where it is cheap**, and flush at the transition to the background as a backstop. 3. **Treat memory as a cache.** Anything in memory may have to be rebuilt from saved UI state and disk. 4. **Restore by intent.** An invisible OS kill should bring the user back where they were; a deliberate swipe-away is a request for a fresh start. ## Where platforms and frameworks differ The names and the number of states differ: one platform exposes the visible-but-inactive moment as a named state, the other surfaces it through the screen's own pause; cross-platform frameworks map their own app-state values onto both. A design answer should name the **behaviour** (visible or not, running or not, kept in memory or not), because that is what is true everywhere, and leave the specific callbacks to each platform. ## Common mistakes - Assuming a background app keeps running normally, so timers and requests "just finish". - Writing the save step into a shutdown handler that the OS is not obliged to call. - Treating a relaunch after an OS kill as a brand-new session and showing the first screen. - Treating a swipe-away and an OS kill as the same event, when users expect different outcomes.

  • Why can't the app just save the draft at the moment it is about to be terminated?
    Because that moment is not reliable. When the OS reclaims a background or suspended process for memory, neither native platform guarantees that any teardown code runs, and a crash skips it as well. The last transition the app is dependably told about is leaving the foreground, so the save happens there, and better still continuously while the user edits.
  • Is a user swiping the app away the same event as the OS terminating it in the background?
    Both end the process, but they mean different things. A swipe-away is a deliberate dismissal, and users expect a fresh start; one platform discards the screen's saved UI state along with it. An OS kill is invisible, and users expect to return exactly where they were. The design restores after an OS kill and starts clean, perhaps offering the saved draft, after a dismissal.

  • The OS always lets the app run a save step before killing it.
  • A suspended app keeps its timers and network calls running, only slower.
  • Background means full CPU time until the user comes back.
  • Termination only happens when the user swipes the app away.
  • Whatever is in memory will still be there when the user returns.
open as a page

In a mobile loan-application form, which state belongs in memory, which in small saved UI state and which on disk, and why?

level: middleimportance: must knowfreq 66%

basics

~20 s

Memory holds the loaded screen state; it survives a UI rebuild but not process death. Small saved UI state holds the draft's identifier and step index needed to rebuild. Disk holds the draft and the ID photo, which must survive everything.

open as a page

For a mobile loan-application app, how should restoring the user's place differ after an OS kill, a user swipe-away, and a return hours later with an expired session?

level: middleimportance: should knowfreq 40%

basics

~20 s

After an OS kill, restore exactly where the user was. After a swipe-away, start fresh and offer the saved draft. After hours away, still return them to their place, but put sign-in first if the session expired and refresh time-sensitive data.

open as a page

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?

level: seniorimportance: should knowfreq 60%

basics

~20 s

The 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.

open as a page

A loan-application app is killed seconds after the user taps submit, before any response arrives. On relaunch, how should it decide whether to resume, resubmit or show the result?

level: seniorimportance: should knowfreq 47%

basics

~20 s

Before sending, persist a submission record holding a client-generated application identifier and a sending status. On relaunch, sending means the outcome is unknown: ask the server about that identifier, or resend reusing it, never with a new one.

open as a page