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.
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.
activity_main.xml
Step 3: Working with MainActivity.java file
Now In MainActivity.java file, create an object of TextView and map the components(TextView) with their id.
// Initializing thetextView
TextView textView;
textView = findViewById (R.id.textView);
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
// When the task is over it will print 00:00:00 there
public void onFinish() {
textView.setText(“00:00:00”);
}
}.start();
The complete code for the MainActivity.java file is given below.
MainActivity.java
Output: Run on Emulator
PulseCountDown
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 referPulseCountDown in Android with Example.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Please Login to comment...