0

I've seen quite a few examples of 'schedule' being used like this:

Timer().schedule(1000) {
    // code to execute after delay
}

However, when I try to use it like this the function needs me to supply some sort of 'TimerTask' and I haven't seen anything about that.

So my question is how do you properly use schedule?

  • 1
    Can you give a link to one of these samples? You would need an extension function to make this possible since TimerTask is not an interface and therefore can't be specified as a lambda. And I don't see any extension functions for Timer in [the list of Jetpack extensions](https://developer.android.com/kotlin/ktx/extensions-list). – Tenfour04 Jul 18 '22 at 19:44
  • https://developer.android.com/reference/java/util/TimerTask – Martin Zeitler Jul 18 '22 at 20:31
  • Here's an example: https://stackoverflow.com/questions/43348623/how-to-call-a-function-after-delay-in-kotlin It's another stack overflow discussion and multiple people suggested using schedule like this. – Kiss Gergő Jul 19 '22 at 08:24

0 Answers0