I\'m using postDelayed
method of the Handler
in order to perform an action after certain amount of time:
private static int time_to
KOTLIN VERSION: (#Muhammed Refaat's Answer):
var myHandler = Handler()
private val TIME_TO_WAIT: Long = 2000
var myRunnable = Runnable {
// your code here
}
fun start() {
myHandler.postDelayed(myRunnable, TIME_TO_WAIT)
}
fun stop() {
myHandler.removeCallbacks(myRunnable)
}
fun restart() {
stop()
start()
}