Using a Handler to execute code after a delayed amount of time

suggest change

Executing code after 1.5 seconds:

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        //The code you want to run after the time is up
    }
}, 1500); //the time you want to delay in milliseconds

Executing code repeatedly every 1 second:

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    @Override
    public void run() {
        handler.postDelayed(this, 1000);
    }
}, 1000); //the time you want to delay in milliseconds

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents