Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { // some code to execute after a delay } }, 1000); // delay time in millisecondsIn this example, the postDelayed method is used to run a piece of code after a delay of 1 second (1000 milliseconds). Package library: The android.os.Handler class is part of the Android SDK, which is available in the android.os package.