Press the buttons. Every one of them makes Android call a different method on the same object — and the log on the right is the proof.
Launch it. Let the clock run for a few seconds. Then press Home, wait, and come back — the seconds are still there. Now press Rotate. They are gone.
Do not answer yet. Demo 02 fixes it, and it only lands if they have felt the loss first.
Do not make them memorise the ring. Three pairs carry the whole idea, and each pair answers one question about the activity.
Fires once per activity instance. This is the pair that decides whether the object exists at all.
The user can see the screen, or cannot. The object is still alive during onStop() — just off screen.
Does the activity have the focus? A dialog on top takes the focus without hiding the activity.
// the activity is destroyed and rebuilt, in this exact order onPause() onStop() onDestroy() // the old object is gone for good onCreate(savedInstanceState = null) // a brand new object onStart() onResume()
Photo Anton Makarenko · Pexels #1078057 · the Stopwatch app is the thread that runs through this whole lecture.
Because the activity never went through onStop() on its way down.
Rotation is a configuration change: Android takes the activity down to onDestroy() and builds a new one. onRestart() only fires when an existing, still-alive activity comes back from onStop() — which is exactly the Home-and-return case.
Run both paths in the simulator and compare the log. That difference — onRestart() present or absent — is the single fastest way to tell which of the two happened.