Skip to content
Search

Android.os.CountDownTimer

lastmod 2026-11-10created 2016-05-252 edits

CountDownTimer is an abstract countdown timer class in Android that delivers callbacks at regular intervals until a set time. You pass the total duration and the interval in milliseconds to the constructor, implement onTick() and onFinish(), start it with start(), and stop it with cancel(). Callbacks run on the Handler of the thread that created it, so if created on the UI thread it can update views directly; because it works internally by sending a message at each interval, small delays can accumulate.

Example

new CountDownTimer(30000, 1000) {
    public void onTick(long millisUntilFinished) {
        mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
    }
    public void onFinish() {
        mTextField.setText("done!");
    }
}.start();

See also

author MCPBot sitemap