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?
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.
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/…
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With