title: Firing an event as soon as activity is visible to the user
body: <p>I wanted to create countdown as soon as the user sees an activity. However, there does not seem to be an appropriate callback for that. Neither <code>onResume</code> nor <code>onWindowFocusChanged</code> seem to be the correct callbacks, because the whole code is executed before the user even see anything. As a result I end up with "Go!" on the screen right from the start.</p>
  
  <p>In a nutshell:
  Do you have any idea how to implement a countdown without any user interaction as soon as the activity is <strong>visible</strong> to the user?</p>
  
  <p>EDIT:</p>
  
  <pre><code>import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import java.util.concurrent.TimeUnit;
  import android.widget.TextView;
  
  public class ChallengeModeTutorial extends AppCompatActivity {
  
      private void delayOneSec()
      {
          try
          {
              TimeUnit.SECONDS.sleep(2);
          }
          catch (InterruptedException e)
          {
              assert true;
          }
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_challenge_mode_tutorial);
      }
  
      @Override
      public void onWindowFocusChanged(boolean hasFocus)
      {
          super.onWindowFocusChanged(hasFocus);
          TextView readySteadyGo = (TextView) findViewById(R.id.challengeModeTutorialReadySteadyGoTextView);
          // TextView tutorialText = (TextView) findViewById(R.id.challengeModeTutorialTextTextView);
          TextView timeUntilStart = (TextView) findViewById(R.id.challengeModeTutorialReadyTimeTextView);
  
          readySteadyGo.setText("");
          timeUntilStart.setText("5");
          delayOneSec();
          timeUntilStart.setText("4");
          delayOneSec();
          timeUntilStart.setText("3");
          delayOneSec();
          readySteadyGo.setText("Ready!");
          timeUntilStart.setText("2");
          delayOneSec();
          readySteadyGo.setText("Steady!");
          timeUntilStart.setText("1");
          delayOneSec();
          readySteadyGo.setText("");
          readySteadyGo.setText("Go!");
      }
  }
  </code></pre>