Skip to content

Instantly share code, notes, and snippets.

@grantland
Created July 21, 2011 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save grantland/1096474 to your computer and use it in GitHub Desktop.
Save grantland/1096474 to your computer and use it in GitHub Desktop.
Android Activity Lifecycle
[...] = starting state
States:
not running (dead)
onResume (running)
onStop (minimized)
onPause (screen off)
Launch Application:
[not running|onStop] (onCreate|onRestart) -> onStart -> onResume
Press Home:
[onResume] onPause -> onStop
Press Back:
If back stack is empty:
[onResume] onPause -> onStop -> onDestroy
If back stack is not empty:
[B.onResume] B.onPause -> B.onStop -> B.onDestroy
-> A.onRestart -> A.onStart -> A.onResume
If back stack is not empty and previous activity was cleared for memory:
[B.onResume] B.onPause -> B.onStop -> B.onDestroy
-> A.onCreate -> A.onStart -> A.onResume
Turn Off Screen:
[onResume] onPause
Turn On Screen:
[onPause] onResume
Calling startActivity:
-> B.onCreate -> B.onStart -> B.onResume
[A.onResume] A.onPause -> A.onStop
Rotating
[onResume] onPause -> onStop -> onDestroy -> onCreate -> onStart -> onResume
Freeing more memory:
[onPause] not running
[onStop] not running
[onDestroy] not running
Edge Cases:
onStart -> onStop
Open activity (onStart -> onResume) and open a dialog above it (onPause).
Press home (onStop) and reopen (onStart).
Press home (onStop)
No Activities in back stack
Pressing back to an activity that was cleared due to memory constraints
Reorienting root activity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment