title: How does TimerTask on Android manages threads?
body: <p>I was wondering how the TimerTask is working with threads.</p>
  
  <p>For example, I've got a code that executes a TimerTask, which has a 'run' method which will run on the UI Thread.</p>
  
  <pre><code>class looper extends TimerTask {
  
      public looper() {
  
      }
  
      public void run() {
          runOnUiThread(new Runnable() {
              @Override
              public void run() {
                  timer.schedule(new looper(), new Date(new Date().getTime() + 100));
              }
          });
      }
  }
  </code></pre>
  
  <p>and the timer would start like this:</p>
  
  <pre><code>    timer = new Timer();
      timer.schedule(new looper(), new Date());
  </code></pre>
  
  <p>Will the TimerTask create a new thread? if so, how does <code>runOnUiThread</code> will work? will it move the code to the UI thread?</p>
  
  <p>I've tried to eliminate the need to call the TimerTask again (<code>timer.schedule</code>) and just use an infinite loop inside the <code>run</code> to make calculations - but that would block the UI thread and the app will not respond.</p>
  
  <p>P.S - I must have the code run on the UI thread, because it has to update the UI.</p>
  
  <p>So, what's going on here?</p>