Kotlin定时器循环执行
var timer: Timer? = null;
var timerTask: TimerTask? = null;
fun initTimer() {
timer = Timer()
timerTask = object : TimerTask() {
override fun run() {
val date = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(Date())
// todo
}
};
timer?.schedule(timerTask, 5*1000, 5*1000);
}
fun clearTimer() {
timer?.cancel();
timer = null;
timerTask?.cancel();
timerTask = null;
}
关键词:Kotlin定时器循环
所属分类:代码片段
本文地址:https://me.i-i.me/article/67.html
评论