1// a simple 5 second timer in android studio
2// the first value is the duration of timer in miliseconds
3// and second value is intervale of one tick in miliseconds
4CountDownTimer timer = new CountDownTimer(5000, 1000) {
5 @Override
6 public void onTick(long millisUntilFinished) {
7 // divide the millisUntilFinished by 1000 because it is in miliseconds
8 int sec = Integer.parseInt(String.valueOf(millisUntilFinished / 1000));
9
10 Log.i(TAG, "secs left" + sec );
11
12 binding.timeProgress.setProgress(0);
13 }
14
15 @Override
16 public void onFinish() {
17
18 }
19 };
20
21// and add {timer.start()} where you have to strt the timer
22// and add {timer.cancle()} where you have to cancle it