1

I have added one TimerTask in my android code:

private class MyTimerTask extends TimerTask {

    @Override
    public void run() {
        //do some task...
    }
}

and calling it as follows:

myTimer = new Timer();
//set the rate as 1 min
myTimer.scheduleAtFixedRate(new MyTimerTask(), 0,
                    60*1000);

Now if I turn off the automatic time update(from network) and set the date as tomorrow's date then timer task starts running in every 5 milliseconds.

For this I don't have any clue why its happening and I need to fix this. I have already used handler instead but I want TimerTask to behave properly.

Please help me in this regard...

Martin C.
  • 12,140
  • 7
  • 40
  • 52
Dharsam1990
  • 121
  • 10

1 Answers1

2

Since you use scheduleAtFixedRate and not schedule it tries to catch up with "missed" executions for the last day.

From the API documentation:

With fixed-rate execution, the start time of each successive run of a task is scheduled without regard for when the previous run took place. This may result in a series of bunched-up runs (one launched immediately after another) if delays prevent the timer from starting tasks on time.

Martin C.
  • 12,140
  • 7
  • 40
  • 52