0

I am using a countdown timer to perform a repeating task. I want to be sure what I'm doing is valid since I'm not sure if the countdown timer object gets destroyed when it times out. Same question applies if I call the cancel method. Here is my code:

   public class MyCount extends CountDownTimer
   {
      public MyCount(long millisInFuture, long countDownInterval)
      {
         super(millisInFuture, countDownInterval);
      }

      @Override
      public void onFinish()
      {
         new myAsyncTask().execute();
         this.start();
      }

      @Override
      public void onTick(long millisUntilFinished)
      {
      }
   }
DeeV
  • 35,865
  • 9
  • 108
  • 95
  • Have you tried running this code? And does it work as intended? I have seen problems arise when .cancle() and .start() are called from within the CountDownTimer class. This [post](http://stackoverflow.com/questions/3138348/how-to-stop-cancel-android-countdowntimer) saw this issue as well – Mike L. Oct 12 '11 at 22:01
  • It does appear to work ok. I'm just concerned that the object may have been freed but still in memory, flagged for garbage collection. – Keith Gilman Oct 13 '11 at 13:18

1 Answers1

0

What you are doing is fine. The timer object will be freed only when the object is no longer reachable. That is, you can call timer.start() repeatedly on the same object as you are doing. timer.cancel() also does not free the object. You can call timer.cancel() and then call timer.start() to reset the timer, all on the same object.

Mike L.
  • 589
  • 6
  • 16