CountdownTimer onTick() not getting called

Viewed 2268

I'm using a simple CountDownTimer and calling the onTick() every millisecond:

    final int[] i = new int[1];

    CountDownTimer countDownTimer = new CountDownTimer(1000, 1) {
        @Override
        public void onTick(long millisUntilFinished) {
            Log.i("Time left", millisUntilFinished + "");
            i[0]++;
        }

        @Override
        public void onFinish() {
            Log.i("i = ", i[0] + "");
        }
    };

The problem is though the timer is finishing-up in the correct time, but the onTick() method is not getting called every millisecond. Few of the milliseconds get missing everytime.

I checked it using the logs and found that the value of i[0] was 597 at the end, whereas it should be 999, as it gets +1 every time onTick() is called. Is there a precision error?

5 Answers

You probably didn't call:

countdown.start();
Related