Stay organized with collections
Save and categorize content based on your preferences.
CountDownTimer
public
abstract
class
CountDownTimer
extends Object
Schedule a countdown until a time in the future, with
regular notifications on intervals along the way.
Example of showing a 30 second countdown in a text field:
Kotlin
object : CountDownTimer(30000, 1000) {
override fun onTick(millisUntilFinished: Long) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000)
}
override fun onFinish() {
mTextField.setText("done!")
}
}.start()
Java
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
}
}.start();
The calls to
onTick(long)
are synchronized to this object so that
one call to
onTick(long)
won't ever occur before the previous
callback is complete. This is only relevant when the implementation of
onTick(long)
takes an amount of time to execute that is significant
compared to the countdown interval.
Summary
Public constructors |
CountDownTimer(long millisInFuture, long countDownInterval)
|
Public methods |
final
void
|
cancel()
Cancel the countdown.
|
abstract
void
|
onFinish()
Callback fired when the time is up.
|
abstract
void
|
onTick(long millisUntilFinished)
Callback fired on regular interval.
|
final
CountDownTimer
|
start()
Start the countdown.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
Public constructors
CountDownTimer
public CountDownTimer (long millisInFuture,
long countDownInterval)
Parameters |
millisInFuture |
long : The number of millis in the future from the call
to start() until the countdown is done and onFinish()
is called. |
countDownInterval |
long : The interval along the way to receive
onTick(long) callbacks. |
Public methods
cancel
public final void cancel ()
Cancel the countdown.
onFinish
public abstract void onFinish ()
Callback fired when the time is up.
onTick
public abstract void onTick (long millisUntilFinished)
Callback fired on regular interval.
Parameters |
millisUntilFinished |
long : The amount of time until finished. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# CountDownTimer\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nCountDownTimer\n==============\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/os/CountDownTimer \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\nabstract\nclass\nCountDownTimer\n`\n\n\n`\n\nextends `[Object](/reference/java/lang/Object)`\n\n\n`\n\n`\n\n\n`\n\n|---|---------------------------|\n| [java.lang.Object](/reference/java/lang/Object) ||\n| ↳ | android.os.CountDownTimer |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nSchedule a countdown until a time in the future, with\nregular notifications on intervals along the way.\n\nExample of showing a 30 second countdown in a text field:\n\n### Kotlin\n\n```kotlin\n object : CountDownTimer(30000, 1000) {\n\n override fun onTick(millisUntilFinished: Long) {\n mTextField.setText(\"seconds remaining: \" + millisUntilFinished / 1000)\n }\n\n override fun onFinish() {\n mTextField.setText(\"done!\")\n }\n }.start()\n \n```\n\n### Java\n\n```java\n new CountDownTimer(30000, 1000) {\n\n public void onTick(long millisUntilFinished) {\n mTextField.setText(\"seconds remaining: \" + millisUntilFinished / 1000);\n }\n\n public void onFinish() {\n mTextField.setText(\"done!\");\n }\n }.start();\n \n```\nThe calls to [onTick(long)](/reference/android/os/CountDownTimer#onTick(long)) are synchronized to this object so that one call to [onTick(long)](/reference/android/os/CountDownTimer#onTick(long)) won't ever occur before the previous callback is complete. This is only relevant when the implementation of [onTick(long)](/reference/android/os/CountDownTimer#onTick(long)) takes an amount of time to execute that is significant compared to the countdown interval.\n\n\u003cbr /\u003e\n\nSummary\n-------\n\n| ### Public constructors ||\n|----------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[CountDownTimer](/reference/android/os/CountDownTimer#CountDownTimer(long,%20long))`(long millisInFuture, long countDownInterval) ` |\n\n| ### Public methods ||\n|-----------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| ` final void` | ` `[cancel](/reference/android/os/CountDownTimer#cancel())`() ` Cancel the countdown. |\n| ` abstract void` | ` `[onFinish](/reference/android/os/CountDownTimer#onFinish())`() ` Callback fired when the time is up. |\n| ` abstract void` | ` `[onTick](/reference/android/os/CountDownTimer#onTick(long))`(long millisUntilFinished) ` Callback fired on regular interval. |\n| ` final `[CountDownTimer](/reference/android/os/CountDownTimer) | ` `[start](/reference/android/os/CountDownTimer#start())`() ` Start the countdown. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[java.lang.Object](/reference/java/lang/Object)` ` |---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](/reference/java/lang/Object) | ` `[clone](/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object. | | ` boolean` | ` `[equals](/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](/reference/java/lang/Object)` obj) ` Indicates whether some other object is \"equal to\" this one. | | ` void` | ` `[finalize](/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final `[Class](/reference/java/lang/Class)`\u003c?\u003e` | ` `[getClass](/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`. | | ` int` | ` `[hashCode](/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object. | | ` final void` | ` `[notify](/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` `[notifyAll](/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor. | | ` `[String](/reference/java/lang/String) | ` `[toString](/reference/java/lang/Object#toString())`() ` Returns a string representation of the object. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` `[wait](/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||\n\nPublic constructors\n-------------------\n\n### CountDownTimer\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic CountDownTimer (long millisInFuture, \n long countDownInterval)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `millisInFuture` | `long`: The number of millis in the future from the call to [start()](/reference/android/os/CountDownTimer#start()) until the countdown is done and [onFinish()](/reference/android/os/CountDownTimer#onFinish()) is called. \u003cbr /\u003e |\n| `countDownInterval` | `long`: The interval along the way to receive [onTick(long)](/reference/android/os/CountDownTimer#onTick(long)) callbacks. \u003cbr /\u003e |\n\nPublic methods\n--------------\n\n### cancel\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic final void cancel ()\n```\n\nCancel the countdown.\n\n\u003cbr /\u003e\n\n### onFinish\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onFinish ()\n```\n\nCallback fired when the time is up.\n\n\u003cbr /\u003e\n\n### onTick\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onTick (long millisUntilFinished)\n```\n\nCallback fired on regular interval.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|-----------------------|---------------------------------------------------|\n| `millisUntilFinished` | `long`: The amount of time until finished. \u003cbr /\u003e |\n\n### start\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic final CountDownTimer start ()\n```\n\nStart the countdown.\n\n\u003cbr /\u003e\n\n| Returns ||\n|--------------------------------------------------------|--------|\n| [CountDownTimer](/reference/android/os/CountDownTimer) | \u003cbr /\u003e |"]]