CountDownTimer in android - how to restart it

后端 未结 5 1410
攒了一身酷
攒了一身酷 2021-01-04 03:26

I to restart a CountDownTimer. I read a lot of question here but no one of the answer helped me. When I use the following code

if(Const.counter != null){
            


        
5条回答
  •  时光取名叫无心
    2021-01-04 04:15

    private fun startTimer() {
        var timeInMilliSeconds = 11000L
        val countDownTimer: CountDownTimer = object : CountDownTimer(timeInMilliSeconds, 1000) {
            override fun onFinish() {
                Timber.d("Times Up!")
                setupResult("")
                this.cancel()
                timeInMilliSeconds = 11000L
                this.start()
            }
    
            override fun onTick(p0: Long) {
                val seconds = (p0 / 1000) % 60
                Timber.d("Timer: $p0")
                timer?.text = "$seconds"
            }
        }
        countDownTimer.start()
    }
    

提交回复
热议问题