I need to display a timer with hours, minutes and seconds. Currently I use android.os.CountDownTimer(1000*60*60, 1000). I have a feeling it's not a perfect fit for my needs, because I don't need it to stop, so I resort to entering huge values as the countdown value.
Am I perhaps missing another method for showing time ticks, indefinitely?
In my case the example above start working only after i made changes like this:
private final Runnable mUpdateTimeTask = new Runnable() {
@Override
public void run() {
final long start = 0;
// long millis = SystemClock.uptimeMillis() ;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
if (seconds < 10) {
waitingTime_Time.setText("" + minutes + ":0" + seconds);
} else {
waitingTime_Time.setText("" + minutes + ":" + seconds);
}
mHandler.postAtTime(this,
start + (((minutes * 60) + seconds + 1) * 1000));
}
};
mStartTime = System.currentTimeMillis(); - returns the value much more than mStartTime = System.currentTimeMillis();
and that's cause negative value to update.
But with setting start time to zero, timer updates every 100 millisec.
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