Android – Run a thread repeatingly within a timer

Just simply use below snippet

private final Handler handler = new Handler();
private Runnable runnable = new Runnable() {
    public void run() {
         //
         // Do the stuff
         //

         handler.postDelayed(this, 1000);
    }
};
runnable.run();

To stop it use

handler.removeCallbacks(runnable);

Should do the trick.

Leave a Comment