java set interval code example
Example 1: java setinterval equivalent
new Timer().scheduleAtFixedRate(new TimerTask(){
@Override
public void run(){
Log.i("tag", "A Kiss every 5 seconds");
}
},0,5000);
Example 2: js setinterval
function func(){
console.log("Ran")
}
setInterval(func,1000)
Example 3: javascript setinterval
setInterval(function() {
}, 1000);
Example 4: équivalent setTimeInterval java
Handler handler = new Handler(Looper.getMainLooper());
Runnable runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(this, milliseconds)
}
};
handler.postDelayed(runnable, milliseconds);
handler.removeCallbacks(runnable);