我是靠谱客的博主 超级柠檬,这篇文章主要介绍kotlin计时器,现在分享给大家,希望可以做个参考。

package com.airiche.sunchip.utils

import android.os.CountDownTimer
import android.os.Looper
import android.util.Log
import com.airiche.sunchip.app.SpeechApp

internal class MyCountUnick(millisInFuture: Long, countDownInterval: Long) : CountDownTimer(millisInFuture, countDownInterval) {

    private var TAG: String = "MyCountUnick"
    override fun onTick(millisUntilFinished: Long) {
        Log.e(TAG, "倒计时中====" + millisUntilFinished)
    }

    override fun onFinish() {
        //倒計時結束如果狀態還沒有改變,那麼就是說不說話了 可以開始退出了
        Log.e(TAG, "倒计时结束====")
        
      
    }


    companion object {
        var myCountUnick: MyCountUnick? = null
        val mMillisInFuture = 8 * 1000L
        val mCountDownInterval = 1000L
      
        fun setStartMyCount() {
            if (myCountUnick != null) {
                myCountUnick!!.cancel()
            }
         
            myCountUnick = MyCountUnick(mMillisInFuture, mCountDownInterval)
            myCountUnick!!.start()
        }
    }
}

可重复启动:启动方式: 

//開啟一個四秒的計時器更改一個提示狀態
object : Thread() {
    override fun run() {
        super.run()
        Looper.prepare()
        MyCountUnick.setStartMyCount(false);
        Looper.loop()
    }
}.start()

如果需要重复启动最好加上线程,要不然回报Looper异常

最后

以上就是超级柠檬最近收集整理的关于kotlin计时器的全部内容,更多相关kotlin计时器内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部