Resuming Android countdown timer

Sasaki

I have been trying to code for a countdown timer with CountDownTimer, and make it able to resume from the stop time. So far I was able to refer to the other question and come up with this.

public void onClick(View v) {
    getResume();

    if ( getResume()==0) {
        countDownTimer.start();
        timerHasStarted = true;
        startB.setText("STOP");
        setResume(1);
        Toast.makeText(this, getResume()+"",Toast.LENGTH_LONG).show();
    } else if (getResume()==1) {
        countDownTimer.cancel();
        timerHasStarted = false;
        startB.setText("RESTART");
        setResume(2);
        Toast.makeText(this, getResume()+"",Toast.LENGTH_LONG).show();
    } else if (getResume()==2){
        CountDownTimer rcdt = new MyCountDownTimer(s1, interval);
        rcdt.start();
        setResume(1);
    }

}

So getResume() is just to get global int resume, which I thought I could use to act as a switch, since timerHasStarted was not helping me very much. However, since I am creating the new timer when resume is 2, I was not able to resume the timer more than once. This code only let me resume once because it is different timer, and after rcdt.start() happens I can't even .cancel(). Clearly I am missing an important concept, but I could not find out by searching. https://gist.github.com/bverc/1492672 unlike this case, I just make the milisuntilfinished = s1, and using it to start new timer. Is this way to go? or is there some way to make the code above work? Please help!

yotam hadas

try to replace this line (in your if==2)

        CountDownTimer rcdt = new MyCountDownTimer(s1, interval);

with

countDownTimer= new MyCountDownTimer(s1, interval);

let me know if its works and fi you udnerstood what was the problem, if it was the problem but you didnt understood what was wrong I will post explanation.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Reset countdown timer in Android when switching between activities

From Dev

JQuery countdown timer with milliseconds

From Dev

Android Countdown Timer Circular Progress Bar doesn't match with timer

From Dev

Super simple js Countdown timer on android?

From Dev

Android Dialog with CountDown TImer

From Dev

Countdown timer not stopping at 0

From Dev

Multiple Countdown Timer in Expandable Listview Android not working

From Dev

How to Sync countdown timer with Server from Android Application

From Dev

Setting a countdown timer with time picker dialog android

From Dev

How to use the chronometer as a countdown timer in Android

From Dev

Start another timer in Countdown timer

From Dev

Countdown Timer with Input Field

From Dev

set different times android countdown timer

From Dev

android countdown timer cancel vs timeup

From Dev

Super simple js Countdown timer on android?

From Dev

Android - Properly creating and countdown of timer?

From Dev

android how to use calender with countdown timer in adapter class?

From Dev

Start countdown timer when time is chosen from Time Picker in android

From Dev

Android ProgressBar timer countdown

From Dev

Android Dialog with CountDown TImer

From Dev

Faster Countdown timer in android

From Dev

Android User input to countdown timer

From Dev

Android How to Change countdown Timer values at runtime

From Dev

Android TimePickerDialog selected time not passing through to the actual Countdown Timer

From Dev

Android Studio: Countdown timer which is also running when the app is closed

From Dev

Android Countdown Timer - Loop through ArrayList restarting timer with List Value

From Dev

Reset Countdown Timer with new Parameters Android

From Dev

Best way for android background countdown timer

From Dev

Pausing and resuming swing Timer

Related Related

  1. 1

    Reset countdown timer in Android when switching between activities

  2. 2

    JQuery countdown timer with milliseconds

  3. 3

    Android Countdown Timer Circular Progress Bar doesn't match with timer

  4. 4

    Super simple js Countdown timer on android?

  5. 5

    Android Dialog with CountDown TImer

  6. 6

    Countdown timer not stopping at 0

  7. 7

    Multiple Countdown Timer in Expandable Listview Android not working

  8. 8

    How to Sync countdown timer with Server from Android Application

  9. 9

    Setting a countdown timer with time picker dialog android

  10. 10

    How to use the chronometer as a countdown timer in Android

  11. 11

    Start another timer in Countdown timer

  12. 12

    Countdown Timer with Input Field

  13. 13

    set different times android countdown timer

  14. 14

    android countdown timer cancel vs timeup

  15. 15

    Super simple js Countdown timer on android?

  16. 16

    Android - Properly creating and countdown of timer?

  17. 17

    android how to use calender with countdown timer in adapter class?

  18. 18

    Start countdown timer when time is chosen from Time Picker in android

  19. 19

    Android ProgressBar timer countdown

  20. 20

    Android Dialog with CountDown TImer

  21. 21

    Faster Countdown timer in android

  22. 22

    Android User input to countdown timer

  23. 23

    Android How to Change countdown Timer values at runtime

  24. 24

    Android TimePickerDialog selected time not passing through to the actual Countdown Timer

  25. 25

    Android Studio: Countdown timer which is also running when the app is closed

  26. 26

    Android Countdown Timer - Loop through ArrayList restarting timer with List Value

  27. 27

    Reset Countdown Timer with new Parameters Android

  28. 28

    Best way for android background countdown timer

  29. 29

    Pausing and resuming swing Timer

HotTag

Archive