if (handlerIdleProgress == null){ handlerIdleProgress = new Handler(); //starting the handler that manages idle progress final long[] cyclesLeft = {secondsElapsed}; //this is to make the value available to "run()". just see it as a long updaterIdleProgress = new Thread() { @Override public void run() { long start = System.currentTimeMillis(); //i take the start time List areas = Utils.compileDungeonList(); //i list the dungeons for "for" iteration while (System.currentTimeMillis() - start < 50 && cyclesLeft[0] > 0){ //if ran for < 50ms && cycles are left for (Area e : areas){ e.tick(); //i do a thing for each area (practically, next turn) } cyclesLeft[0] -= 1; //subtract a cycle } //after running for 50 ms, if there are cycles left to compute, i run it again after 25ms. //this is to prevent ANR, as freezing the screen for 5+ seconds isn't ideal if (cyclesLeft[0] > 0) handlerIdleProgress.postDelayed(this, 25); else { //at the end of the cycle, i start the normal execution. it just does one cycle per second //while the app is open if(handlerUI == null) { handlerUI = new Handler(); updaterUI = new Thread() { @Override public void run() {/* ... */}