Adil Saiyad
Adil Saiyad

Reputation: 1592

Android CountDownTimer showing delay time after some specific time like 15-20 mins

I have implemented simple timer but i faced time delay issue when device screen continues active and timer running after 15-20 mins it's show 1-2 minutes delay with exact time.

long timerDuration = Long.MAX_VALUE; // Use a very large number to simulate indefinite counting

    // Create and start the CountDownTimer
    breakTimer = new CountDownTimer(timerDuration, 1000) { // Count down in intervals of 1 second
        @Override
        public void onTick(long millisUntilFinished) {
            // Increment the break time

            // Calculate hours, minutes, and seconds
            int h = totalBreakSeconds / 3600;
            int m = (totalBreakSeconds % 3600) / 60;
            int s = totalBreakSeconds % 60;

            // Update the UI
            breakHours.setText(String.format("%02d", h));
            breakMinutes.setText(String.format("%02d", m));
            breakSeconds.setText(String.format("%02d", s));

            totalBreakSeconds++;
        }

        @Override
        public void onFinish() {
            // You can implement logic here if you want to handle the end of the timer
            // For this use case, it will not reach here because of Long.MAX_VALUE
        }
    }.start();

can anyone please help me for resolved this issue.

Upvotes: 0

Views: 25

Answers (0)

Related Questions