Wait for 5 seconds

you can use java handlers to achieve your task:

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
     // Actions to do after 5 seconds
    }
}, 5000);

for more information read the following url:

https://developer.android.com/reference/android/os/Handler.html


just add one-liner with lambda

(new Handler()).postDelayed(this::yourMethod, 5000);

edit for clarification: yourMethod refers to the method which you want to execute after 5000 milliseconds.


See if this works for you. Be sure to import the android.os.Handler

      Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    // yourMethod();
                }
            }, 5000);   //5 seconds

or Kotlin

Handler().postDelayed({
    // yourMethod()
}, 5000)

Tags:

Android

Wait