If you need to do some delayed task in for example your Android App, you can easily achieve this with a Java TimerTask.

This is a short example, where some method ( removeDialog() ) is run with a delay of 2 seconds.

//import statements
import java.util.Timer;
import java.util.TimerTask;
 
//in your method, use the Timer Schedule function:
new Timer().schedule(
    new TimerTask() {
        @Override
        public void run() {
            removeDialog();
        }
    },
    2000
);