String hms = String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished)),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)));
I seriously don't get
1) How minutes - hours work TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished))
2) Why does it always ends with 00:01?
3) How does onTick()
method of CountDowntimer
gets called?
1) How minutes - hours work TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millisUntilFinished))
Don't know why you did this. You can just write
String hms = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished), TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)));
2) Why does it always ends with 00:01?
Yes you are right! In the countdown timer last call will not trigger the onTick() method it will call the below method.
public void onFinish() {
mTextField.setText("00:00");
}
So you can set "00:00" at the onFinish() method shown in the above snippet.
3) How does onTick() method of CountDowntimer gets called?
-onTick() Callback fired on regular interval provided to the CountDowntimer constructor.