In this tutorial we will learn, how to build a simple countdown timer, which shows the remaining time in minutes and seconds. It will have a start/pause button and a reset button which is only visible, if the timer is not running. For this, we will use the CountDownTimer interface and override the onTick and onFinish methods. We will set it’s time in milliseconds and format those milliseconds to minutes and seconds using the String.format method.

Watch the whole playlist:

Source code:

____________________
❗ Subscribe to the channel:

⏯ Watch more tutorials:

㊙ Help translating the videos:

💚 Support the content:

💬 Join the Discord chat:

🎧 Audiobooks and podcasts for programmers:

👶 How to get started with Android development:

📣 Follow Coding in Flow on social media:

Facebook:

Instagram:

Twitter:

Blog:

Nguồn:https://u-os.org/

Xem Thêm Bài Viết Khác:https://u-os.org/cong-nghe

Author

31 Comments

  1. Hahaha beste Englisch..😂😂😂 Man hört so raus, dass du deutscher bist.

  2. tasos xroneas Reply

    is there any way we can make a button to add 10 more minutes to the timer? I tried making a add() method and it momentarily adds 10 mins before the counter gets straight to the original 10 minutes countdown

  3. many thanks from Vietnam! Good things will come to your family! First is my subscription :))

  4. Hakan Özdemir Reply

    why do you use "m" before button and textview definitions?

  5. nochmals vielen Dank, sehr hilfreich, am Ende fehlt natürlich noch ein kurzer "Rassel-Wecker"-Sound wie bei einer Eieruhr ;o)

  6. Clinton Siegel Reply

    Thank you very much!!! You are my 'go-to' for Android knowledge and applied solutions!

  7. Duyen Pham Reply

    Hi, I did the same for you but it didn't work as well as you, can you help me? Thanks

  8. Yigit Sereflioglu Reply

    I can't move the text view with Relative Layout like you do , but I can move it with Constraint Layout.Does this work too ?

  9. I have sort of an odd question. how would i go about making the minutes into tenths of a hour instead of minutes? for example instead of "1:30:00" it would countdown from "1:0.5:00" or "1:05:00"

  10. Albano Bermejo Reply

    Hey, thanks for the tutorial. It is great and very well explained.
    I have to add
    mTimerRunning = false;
    After onCreate otherwise my emulator was crashing. Is this normal. Have I done something wrong?

  11. Cătălin George Feștilă Reply

    This tutorial working well with Android Studio 3.4.1

  12. milesperhour Reply

    Very helpful and straight to the point, just like every tutorial should be!
    Danke sehr!

  13. Umar Ghaffar Reply

    I don't think it is a good tutorial because the time doesn't end properly it stops at 100 milliseconds what if we want to perform an operation on finishing of time but in reality, time is not finishing.

Write A Comment