settimeout in java androd studio 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: é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);