android studio interval timer code example
Example 1: timers in android studio
CountDownTimer timer = new CountDownTimer(5000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
int sec = Integer.parseInt(String.valueOf(millisUntilFinished / 1000));
Log.i(TAG, "secs left" + sec );
binding.timeProgress.setProgress(0);
}
@Override
public void onFinish() {
}
};
Example 2: android timer
private int counter;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Log.e("TimerTask", String.valueOf(counter));
counter++;
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 0, 1000);