Android_Chronometer pause

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;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)