Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android_Chronometer pause

I want to pause chronometer and after I click the button I want to continue chromoneter to count... I search but couldn't a function related this.. how can do it?

like image 285
andveand Avatar asked Apr 08 '11 12:04

andveand


People also ask

How do you pause and resume chronometer on Android?

It should by default start from 00:00 when start() is called, and stop() should stop the timer as it is, and the next call to start should resume the time, and have a reset method to reset it to 00:00.

How do you pause a countDown timer?

Click to start then click again to pause and to resume, click again the timer's text view. This will surelyhelp you stackoverflow.com/questions/3510433/…

How do I turn off chronometer on Android?

To stop the chronometer, use the stop method. The start and stop methods do not change the base, they simply start and stop the display of the count in the text view. That is, once started, the Chronometer never stops counting. However, you can reset the base by invoking setBase with a new starting point.


1 Answers

You are gonna need a variable that keeps track on the time that has passed since the Chronometer was started:

long timeWhenStopped = 0; 

Update the value of the variable when you stop the chronometer like this:

timeWhenStopped = mChronometer.getBase() - SystemClock.elapsedRealtime(); mChronometer.stop(); 

We will also use this variable to adjust the chronometer before starting it:

mChronometer.setBase(SystemClock.elapsedRealtime() + timeWhenStopped); mChronometer.start(); 

And finally if you have a way to reset your chronometer then you should remember to also reset the timeWhenStopped variable. Something like this:

mChronometer.setBase(SystemClock.elapsedRealtime()); timeWhenStopped = 0; 
like image 79
HenrikS Avatar answered Sep 20 '22 00:09

HenrikS