chronometer doesn't stop in android
Sorry, but I've found a solution myself and it seems much simpler:
In your activity, declare a member variable(e.g. lastPause) to record the time of your last pause:
private long lastPause;
Start your timer (assume the variable of your timer is crono):
crono.setBase(SystemClock.elapsedRealtime());
crono.start();
Pause your timer each time using:
lastPause = SystemClock.elapsedRealtime();
crono.stop();
Resume your timer each time using:
crono.setBase(crono.getBase() + SystemClock.elapsedRealtime() - lastPause);
crono.start();
I've not tested the precision precisely yet as it seems to be ok by my eyes :]
From the Chronometer doc
Stop counting up. This does not affect the base as set from setBase(long), just the view display.
I dont have any android dev environment right now, so cant investigate on it more :(
Edit:
is it the code you have based your code on ? It seems to use setBase
to the current time on stop