title: Android/Java - pause thread
body: <p>I'm new to this, so maybe it's trivial to everybody, but I just can't figure out, why this isn't working. I've read about it, tried many way, and still not working. So I want to pause a thread in android (java). I want this to run, freeze the screen for 1 sec, and continue working. That's all. Why isn't this working?</p>
  
  <pre><code>public class Game extends Activity {
  
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.game);
  
          runner.join();
          runner.start();
  
          // do stuff
  
          pause();
  
          // do stuff
  
  
  }
  
  private boolean running = true;
  private boolean paused = false;
  
  public void setRunning(boolean run) {
      running = run;
  }
  
  public void pause() {
      paused = true;
  }
  
  Thread runner = new Thread() {
  
      public void run() {
  
          while (running) {
  
              try {
  
                  //do stuff
  
                  Thread.sleep(100);
  
                  while (paused) {
                      try {
                          Thread.sleep(1000);
                      } catch (Exception e) {
                      } finally {
                          paused = false;
                      }
                  }
  
              } catch (Exception e) {
              }
          }
  
      }
  
  };
  </code></pre>
  
  <p>}</p>