App & component lifecycle

Android Activity/Fragment lifecycle + configuration changes + process death; iOS scene phases + background execution. "What happens on rotation mid-task?" is the archetypal lifecycle probe.

About 22 min read3-question knowledge check

The mental model

Think of a stage play where the director (the OS) can call your actor on and off stage at will, and — this is the part that trips people up — can also fire the entire cast and rebuild the set from scratch while the audience is still watching, then expect the scene to resume exactly where it left off. The lifecycle is the set of cues the director gives you: "you're on", "you're visible but not interactive", "you're leaving", "the set is being torn down". Your job is to save and restore the scene at the right cues so the audience never notices the rebuild.

The reason this matters more on mobile than anywhere else is that the "rebuild" happens constantly and for mundane reasons. A configuration change — the user rotates the device, switches to dark mode, changes the font size, or plugs in a keyboard — destroys and recreates the Android Activity by default. Separately, process death — the OS reclaiming your backgrounded app for memory — wipes everything in RAM. These two are different events with different survival mechanisms, and confusing them is the single most common lifecycle mistake.

The archetypal interview probe is exactly this collision: *"the user rotates the device mid-upload — what happens?"* A good answer separates the concerns: the upload work must not be tied to the Activity (or it dies on rotation), and the UI state (progress, the form the user typed) must be hoisted somewhere that survives recreation. An answer that says "I'd use android:configChanges to prevent rotation from recreating the Activity" reveals someone patching the symptom instead of understanding the model — that flag suppresses recreation but breaks resource reloading and does nothing for process death.

The unifying idea: the lifecycle exists because your UI is disposable and your state is not. Design so that view objects can be thrown away and rebuilt cheaply, while the data they display lives somewhere more durable than the view.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision
App & component lifecycle — Mobile lesson · PrepAtlas Tech