java setinterval equivalent

Solutions on MaxInterview for java setinterval equivalent by the best coders in the world

showing results for - "java setinterval equivalent"
Eleonora
09 Jun 2017
1new Timer().scheduleAtFixedRate(new TimerTask(){
2    @Override
3    public void run(){
4       Log.i("tag", "A Kiss every 5 seconds");
5    }
6},0,5000);
7// SETINTERVAL
8
Ariana
01 Oct 2019
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);
similar questions
java run code at interval