Skip to content
Related Articles
Open in App
Not now

Related Articles

CountDownTimer in Android with Example

Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 24 Aug, 2022
Improve Article
Save Article

CountDownTimer app is about setting a time that moves in reverse order as it shows the time left in the upcoming event. A CountDownTimer is an accurate timer that can be used for a website or blog to display the count down to any special event, such as a birthday or anniversary. Likewise, here let’s create an Android App to learn how to create a simple Countdown App. So let’s begin app creation step by step towards its completion.



Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Working with activity_main.xml file

In the activity_main.xml file add only a TextView to display the CountDownTimer. Below is the complete code for the activity_main.xml file.



Step 3: Working with file

Now In file, create an object of TextView and map the components(TextView) with their id. 

// Initializing thetextView

TextView textView;

textView = findViewById (;

Schedule a countdown until a time in the future, with regular notifications on intervals along the way. Example of showing a 50-second countdown in a text field:

new CountDownTimer(50000, 1000) {

           public void onTick(long millisUntilFinished) {

               // Used for formatting digit to be in 2 digits only

               NumberFormat f = new DecimalFormat(“00”);

               long hour = (millisUntilFinished / 3600000) % 24;

               long min = (millisUntilFinished / 60000) % 60;

               long sec = (millisUntilFinished / 1000) % 60;

               textView.setText(f.format(hour) + “:” + f.format(min) + “:” + f.format(sec));


           // When the task is over it will print 00:00:00 there

           public void onFinish() {




The complete code for the file is given below.


Output: Run on Emulator


PulseCountDown in Android is an alternative to CountDownTimer. It is very easy to implement PulseCountDown instead of CountDownTimer because PulseCountDown provides a default layout with some beautiful animations. By default start value of PulseCountDown is 10 and the end value is 0. Suppose there needs a quiz app, and in that add time limit to answer a question there PulseCountDown can be used. To implement PulseCountDown please refer PulseCountDown in Android with Example.

pulse countdown

Pulse Count Down

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!