👉 문제

- 위와 같이 Interval Time을 5초로 지정하면 5-4-3-2-1-0이 떠서 시작 초가 휙 지나가는 현상 발생
👉 기존 코드
private void setupAndStartTimer() {
countDownTimer = new CountDownTimer(timeLeftInMillis, 100) {
@Override
public void onTick(long millisUntilFinished) {
timeLeftInMillis = millisUntilFinished;
updateTimerText(millisUntilFinished);
}
@Override
public void onFinish() {
if (currentSet > 1) {
notifyInterval();
currentSet--;
startTimer();
} else {
notifyCompletion();
}
}
}.start();
}
👉 문제 원인 및 해결 방안
- 시작 초부터 updateTimerText(남은 시간 View에 update 하는 메서드)를 실행
- countDownTimer가 100ms 간격으로 실행되기 때문에 간헐적으로 시작 초가 보임
- ⇒ 시작 초는 보이지 않게 수정
👉 수정한 코드
private void setupAndStartTimer() {
countDownTimer = new CountDownTimer(timeLeftInMillis, 100) {
@Override
public void onTick(long millisUntilFinished) {
timeLeftInMillis = millisUntilFinished;
if (intervalTime != (int)timeLeftInMillis / 1000) {
updateTimerText(millisUntilFinished);
}
}
@Override
public void onFinish() {
if (currentSet > 1) {
notifyInterval();
currentSet--;
startTimer();
} else {
notifyCompletion();
}
}
}.start();
}