Android – loop part of the code every 5 seconds
Using a CountDownTimer as in one of the other answers is one way to do it. Another would be to use a Handler and the postDelayed method: private boolean started = false; private Handler handler = new Handler(); private Runnable runnable = new Runnable() { @Override public void run() { final Random random = new … Read more