Convert indefinitely running Runnable from java to kotlin
Lambda-expressions do not have this
, but object expressions (anonymous classes) do.
object : Runnable {
override fun run() {
handler.postDelayed(this, 1000)
}
}
A slightly different approach which may be more readable
val timer = Timer()
val monitor = object : TimerTask() {
override fun run() {
// whatever you need to do every second
}
}
timer.schedule(monitor, 1000, 1000)
From: Repeat an action every 2 seconds in java