How to change/reset handler post delayed time?

后端 未结 3 1600
春和景丽
春和景丽 2020-12-09 11:41

I\'m using postDelayed method of the Handler in order to perform an action after certain amount of time:

private static int time_to         


        
3条回答
  •  独厮守ぢ
    2020-12-09 12:24

    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()
    }
    

提交回复
热议问题