1// Param is optional, to run task on UI thread.
2Handler handler = new Handler(Looper.getMainLooper());
3Runnable runnable = new Runnable() {
4 @Override
5 public void run() {
6 // Do the task...
7 handler.postDelayed(this, milliseconds) // Optional, to repeat the task.
8 }
9};
10handler.postDelayed(runnable, milliseconds);
11
12// Stop a repeating task like this.
13handler.removeCallbacks(runnable);