Thursday, 3 February 2011

Reloading a WebView every x seconds

If you load a page using WebView and want to reload that page to show the latest updates etc. java has an easy solution for that:
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); exec.scheduleAtFixedRate(new Runnable() { @Override public void run() { Shout.loadUrl(""+konto); } }, 10, 20, TimeUnit.SECONDS);

So this piece of code simply reloads the page every 20 seconds with a 20 second initial delay which is very ideal for updating my shoutbox. Of course, you can change the WebView with whatever code you need to execute between fixed intervals.


  1. This is awesome, if you just could do this to an iPhone.. :D