Android Activity lifecycle: Simple example class (source code template)

With all apologies to Google for copying and pasting this block of source code, in my opinion, this simple example is so good at explaining the Android Activity lifecycle so well that it needs to stand out on its own page:

public class ExampleActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // The activity is being created.
  }

  @Override
  protected void onStart() {
    super.onStart();
    // The activity is about to become visible.
  }

  @Override
  protected void onResume() {
    super.onResume();
    // The activity has become visible (it is now "resumed").
  }

  @Override
  protected void onPause() {
    super.onPause();
    // Another activity is taking focus (this activity is about to be "paused").
  }

  @Override
  protected void onStop() {
    super.onStop();
    // The activity is no longer visible (it is now "stopped")
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
    // The activity is about to be destroyed.
  }
}

Normally a picture is worth a thousand words, but for some reason, my brain can absorb the comments in this source code much more easily than it can the typical Activity lifecycle diagram.

This source code comes from the much larger Android Activities documentation.