Run code after milliseconds (and repeat it)

Run code after a specific time or build a timer and repeat it using Handler.


Libraries

Code Snippet
Handler h = new Handler();
int delay = 1000; //milliseconds

h.postDelayed(new Runnable(){
    public void run(){
        //do something
        h.postDelayed(this, delay);
    }
}, delay);


Implementation

Use the code above and replace "// do something" with your function.





Comments
  • mode_editWrite a comment



  • forumComments




Embed Code

We provide special containers which include the full snippet and a link to this site. So for example when you make a tutorial and you are using code from this site, you can use one of the following snippet embeddings:

Load Preview Get Code Close Preview







    Share
    Rating
    thumb_up 1 thumb_down
    Author
    Thorolus

    I'm the head developer and co-founder of GlovilGames Studios (glovilgames.com) and other platforms GlovilGames created, like vsnippets.com, worth-calculator.net, python-obfuscator.com and some mobile apps and games.

    Tags
    Android
    time



    Informations

    posted on 2016-10-28 15:45:20

    viewed 75 times

    snippet's UUID is 58135670046ef

    Similar Snippets