Skip to content

Instantly share code, notes, and snippets.

@nadar71
Created October 21, 2020 09:39
Show Gist options
  • Save nadar71/d0fa591de5fe30d5ddf1103e64636dae to your computer and use it in GitHub Desktop.
Save nadar71/d0fa591de5fe30d5ddf1103e64636dae to your computer and use it in GitHub Desktop.
Count Down timer utility
import android.os.CountDownTimer
class CountdownTimerUtility {
var countdowntimer: CountDownTimer? = null
//start timer function
fun startTimer(duration: Long, countDownStep: Long, executeOnFinish: ()->Unit) {
countdowntimer = object : CountDownTimer(duration, countDownStep) {
override fun onTick(millisUntilFinished: Long) {}
override fun onFinish() {
executeOnFinish()
}
}
countdowntimer!!.start()
}
fun cancelTimer() {
if (countdowntimer != null)
countdowntimer!!.cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment