title: CountDownTimer onFinish() not called if I call cancel() when activity is pausing
body: <p>I've got an activity that plays some music via a <code>MediaPlayer</code>. Normally when I want to stop the song, I pass the MediaPlayer to a <code>CountDownTimer</code> that fades the volume to zero, and then releases the MediaPlayer. This seems to work fine, except that I'm having a problem when my activity pauses, such as after touching the home button.</p>
  
  <p>I'm calling <code>cancel()</code> on the CountDownTimer in <code>onPause</code>, but it seems that since the activity is pausing, the CountDownTimer never receives the message before it is destroyed (?), and thus the <code>finish()</code> of CountDownTimer is not called.</p>
  
  <p>The result of this is that after exiting the application, the music continues to play at whatever volume was last set in the CountDownTimer, but it never finishes. So now I'm stuck out of my application with the MediaPlayer running and no way to stop it (very bad).</p>
  
  <p>Is it normal for a CountDownTimer to not get called <code>onFinish</code> when the activity is exiting, even if I called cancel?</p>
  
  <p>This is my code:</p>
  
  <pre><code>public void StopSong(boolean fadeout){
      musicPlaying = false;
      if(_player != null) {
          final int fadeTime = 1000;
          CountDownTimer timer = new CountDownTimer(fadeTime,50) {
              final private MyMusicPlayer mFadePlayer = _player;
  
              @Override
              public void onTick(long millisUntilFinished) {
                  mFadePlayer.setFade((float)millisUntilFinished / (float)fadeTime);
                  Log.d("tag", "Fade timer " + millisUntilFinished+ "ms remaining.");
              }
  
              @Override
              public void onFinish() {
                  mFadePlayer.stop();
                  mFadePlayer.release();
                  Log.d("tag", "Fade timer finished, releasing resource.");
              }
          };
          timer.start();
          mFadeTimers.add(timer);
          Log.d("tag", "Song stopping, starting fade timer.");
          _player = null;
      }
  }
  </code></pre>
  
  <p>And in onPause:</p>
  
  <pre><code>    for(CountDownTimer t : mFadeTimers){
          Log.d("tag", "Cancelling fade timer on destroy.");
          t.cancel();
      }
      mFadeTimers.clear();
  </code></pre>
  
  <p>If everything was working fine, I would see the "cancelling fade timer" log message, followed by "Fade timer finished, releasing", but I never get the <code>onFinish()</code> logcat message.</p>
  
  <p>I just see this:</p>
  
  <pre><code> tag     Song stopping, starting fade timer.
   tag     Application exiting, destroying all audio resources
   tag     Cancelling fade timer on destroy.
  </code></pre>
  
  <p>How can I successfully abort all my countdowntimers on exiting the activity?</p>