Skip to content

Instantly share code, notes, and snippets.

@odai-alali
Created February 22, 2018 11:12
Show Gist options
  • Save odai-alali/916d643a13525e1e9a3b2b4516ad1236 to your computer and use it in GitHub Desktop.
Save odai-alali/916d643a13525e1e9a3b2b4516ad1236 to your computer and use it in GitHub Desktop.
The equivalent to a JavaScript setInterval/setTimeout in Android/Java?
// setInterval()
new Timer().scheduleAtFixedRate(new TimerTask(){
@Override
public void run(){
Log.i("interval", "This function is called every 5 seconds.");
}
},0,5000);
// setTimeout()
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
Log.i("timeout","This function is called after 5 seconds.");
}
}, 5000);
@HBFLEX
Copy link

HBFLEX commented Apr 22, 2023

Just in time I was searching for this

@odai-alali
Copy link
Author

Just in time I was searching for this

Happy to help 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment