Wait for 5 seconds

user7320356 picture user7320356 · Jan 15, 2017 · Viewed 78.6k times · Source

I want to wait 5 seconds before starting another public void method. The thread sleep was not working for me. If there is a way of wait() without using Threads I would love to know that.

public void check(){
    //activity of changing background color of relative layout
}

I want to wait 3 seconds before changing the relative layout color.

Answer

seekingStillness picture seekingStillness · Jan 15, 2017

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