rafaelasguerra
rafaelasguerra

Reputation: 2555

Android - Any Timer component that allows to use pause,resume

I'm using a simple countDownTimer

new CountDownTimer(30000, 1000) {

     public void onTick(long millisUntilFinished) {
         mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
     }

     public void onFinish() {
         //do things
     }
  }.start();

But now, I want to call something like

countDown.pause(); countDown.resume();

(storing the remaining time and progress this way):

I know that is not possible with CountDownTimer.

How I can use a timer or handler with the same behaviour of onFinish() method from CountDownTImer?

Upvotes: 2

Views: 191

Answers (1)

Harikrishnan
Harikrishnan

Reputation: 8065

This is a really good library to do exactly what you want : pause-resume-timer

It is basically a subclass of Timer. A really easy to use library. All you need to do is:

//This creates a timer which ticks every 2 seconds, and runs for 20 seconds.
Timer twoSecondTimer = new ExampleTimer(2000l, 20000l);
//Start the timer.
twoSecondTimer.start();
//Pause the timer.
twoSecondTimer.pause();
//Resume the timer
twoSecondTimer.resume();

Upvotes: 1

Related Questions