Created
October 21, 2020 09:39
-
-
Save nadar71/d0fa591de5fe30d5ddf1103e64636dae to your computer and use it in GitHub Desktop.
Count Down timer utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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