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?
3 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;

- 4,170
- 3
- 34
- 33
-
5Maybe I have a weird way of thinking, but the way Chronometer works seems really out of common sense. 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. I will use your method to solve this problem, but I just wonder why Google designed it this way. – Damn Vegetables Aug 01 '18 at 14:52
The two other answers are identical, and work very well on the Chronometer's display, but they have one flaw: timeWhenStopped
, as well as the value returned by getCurrentTime()
, is negative.
Here is my suggestion, base on these two answers:
public class PausableChronometer extends Chronometer {
private long timeWhenStopped = 0;
public PausableChronometer(Context context) {
super(context);
}
public PausableChronometer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PausableChronometer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void start() {
setBase(SystemClock.elapsedRealtime() - timeWhenStopped);
super.start();
}
@Override
public void stop() {
super.stop();
timeWhenStopped = SystemClock.elapsedRealtime() - getBase();
}
public void reset() {
stop();
setBase(SystemClock.elapsedRealtime());
timeWhenStopped = 0;
}
public long getCurrentTime() {
return timeWhenStopped;
}
public void setCurrentTime(long time) {
timeWhenStopped = time;
setBase(SystemClock.elapsedRealtime() - timeWhenStopped);
}
}
You've got to understand SystemClock.elapsedRealtime()
as an indicator for "now". So when we (re)start the chronometer, we shall set the base N
seconds in the past, N
being the timer's current value (0 in case of first start).
Similarly, when stopping the chronometer, the time displayed by the chronometer is the time elapsed between the previously set base (getBase()
) and now (SystemClock.elapsedRealtime()
), hence the subtraction.

- 879
- 9
- 17
-
1The other answers are definitely wrong. This should be the most upvoted answer. – ram Aug 04 '18 at 17:59
I made a PauseableChronometer
class for this.
import android.content.Context;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.widget.Chronometer;
public class PausableChronometer extends Chronometer {
private long timeWhenStopped = 0;
public PausableChronometer(Context context) {
super(context);
}
public PausableChronometer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PausableChronometer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void start() {
setBase(SystemClock.elapsedRealtime()+timeWhenStopped);
super.start();
}
@Override
public void stop() {
super.stop();
timeWhenStopped = getBase() - SystemClock.elapsedRealtime();
}
public void reset() {
stop();
setBase(SystemClock.elapsedRealtime());
timeWhenStopped = 0;
}
public long getCurrentTime() {
return timeWhenStopped;
}
public void setCurrentTime(long time) {
timeWhenStopped = time;
setBase(SystemClock.elapsedRealtime()+timeWhenStopped);
}
}

- 2,496
- 2
- 20
- 40