im new at coding, i dont know even basics but
I need make somekind 20 seconds countdown timer and i didin't found any working tutorials.
I tried my best but always some error came up.
im new at coding, i dont know even basics but
I need make somekind 20 seconds countdown timer and i didin't found any working tutorials.
I tried my best but always some error came up.
pass time
in milliseconds.
var countDownTimer: CountDownTimer? = null //declare it as global variable
fun startCountDown(time: Long) {
countDownTimer = object: CountDownTimer(time,1000){
override fun onFinish() {
Timber.v("Countdown: Finished")
visibility = View.GONE
}
override fun onTick(millisUntilFinished: Long) {
Timber.v("Countdown: $millisUntilFinished")
visibility = View.VISIBLE
updateTimeView(millisUntilFinished)
}
}
countDownTimer?.start()
}
For example:
startCountDown(30000)
, will countdown from 30 to 0.
Note: Don't forget to stop the timer when your app stops:
override fun onStop() {
super.onStop()
countDownTimer?.cancel()
}