Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8663583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:01:18+00:00 2026-06-12T17:01:18+00:00

From my observation the android CountDownTimer countDownInterval between ticks happens to be not accurate,

  • 0

From my observation the android CountDownTimer countDownInterval between ticks happens to be not accurate, the countDownInterval is regularly a few milliseconds longer than specified. The countDownInterval in my specific app is 1000ms, just counting down a certain amount of time with one second steps.

Due to this prolonged ticks I end up having less ticks then wanted when the the countdowntimer runs long enough which screws up the displayed countdown of the time (a 2 second step happens on the UI level when enough additional ms have summed up)

Looking into the source of CountDownTimer it seems possible to twist it so it corrects this unwanted inaccuracy yet I was wondering if there is already a better CountDownTimer available in the java/android world.

Thanks buddies for any pointer …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:01:20+00:00Added an answer on June 12, 2026 at 5:01 pm

    Rewrite

    As you said, you also noticed that the next time in onTick() is calculated from the time the previous onTick() ran, which introduces a tiny error on every tick. I changed the CountDownTimer source code to call each onTick() at the specified intervals from the start time.

    I build this upon the CountDownTimer framework, so cut & paste the source code into your project and give the class a unique name. (I called mine MoreAccurateTimer.) Now make a few changes:

    1. Add a new class variable:

      private long mNextTime;
      
    2. Change start():

      public synchronized final MoreAccurateTimer start() {
          if (mMillisInFuture <= 0) {
              onFinish();
              return this;
          }
      
          mNextTime = SystemClock.uptimeMillis();
          mStopTimeInFuture = mNextTime + mMillisInFuture;
      
          mNextTime += mCountdownInterval;
          mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG), mNextTime);
          return this;
      }
      
    3. Change the Handler’s handlerMessage():

      @Override
      public void handleMessage(Message msg) {
          synchronized (MoreAccurateTimer.this) {
              final long millisLeft = mStopTimeInFuture - SystemClock.uptimeMillis();
      
              if (millisLeft <= 0) {
                  onFinish();
              } else {
                  onTick(millisLeft);
      
                  // Calculate next tick by adding the countdown interval from the original start time
                  // If user's onTick() took too long, skip the intervals that were already missed
                  long currentTime = SystemClock.uptimeMillis();
                  do {
                      mNextTime += mCountdownInterval;
                  } while (currentTime > mNextTime);
      
                  // Make sure this interval doesn't exceed the stop time
                  if(mNextTime < mStopTimeInFuture)
                      sendMessageAtTime(obtainMessage(MSG), mNextTime);
                  else
                      sendMessageAtTime(obtainMessage(MSG), mStopTimeInFuture);
              }
          }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From the Scala API , I got the following example, which does not compile;
How does JWS react to code signing certificate expiration? From my observation it appears
So I have a bunch of hyperlinks on a web page. From past observation
From what I have played around with JQuery Dialog, I made an observation that
Issue When dragging an item from the toolbar to an observation group the item
Answer update, 12/22 : Using Peter Shor's observation that there's a homomorphism between distinct
I have raw observations of 500 numeric values (ranging from 1 to 25000) in
From my website, I have a button which calls a method and then generates
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
from Apple's Documentation : @property(readonly, nonatomic) CMMagneticField magneticField Returns the magnetic field measured by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.