class MainActivity : AppCompatActivity() {
private val delayTime = 100L //延时时间
private val handler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
handler.postDelayed(mRunnable, 1000)
}
private var mRunnable = object : Runnable {
override fun run() {
val now = SystemClock.uptimeMillis()
val next = now + (delayTime - now % delayTime)
Log.e("log", "$next")
handler.postAtTime(this, next)
}
}
}