Search code examples
androidkotlinimageviewwaitpause

How do you tell a function to wait a few seconds in Kotlin?


Kotlin in Android Studio here.

I'm trying to get an imageView to fade into the main view, wait a few seconds, then fade out. For the life of me I can't find any documentation on pausing or waiting anywhere. It's driving me nuts.

How do I tell my function to just chill out and wait for 3 seconds, then continue executing the rest of the function's code?

Ideally, I would have it between:

imageView.startAnimation(animIn)
imageView.startAnimation(animOut)

Any help is very appreciated!

Zoo


Solution

  • You can use Handler,

    Handler().postDelayed(Runnable { 
        //anything you want to start after 3s
    }, 3000)