title: Android ProgressBar: loading with Timer
body: <blockquote>
    <p><strong>Update:</strong>
    This post was from when I was learning android with android 2.2, be sure to check if this is compatible with the api level you are working with.</p>
  </blockquote>
  
  <p>Done alot of looking around for how to load progress bar with a timer, I've tried to use methods posted but always would get a pointer exception and or the testing app would crash at start up.</p>
  
  <p>my question is, lol has anyone ran across any tutorials or examples on how to do this? I'm thinking all i need is a while loop but haven't seen that done on a timer yet. I'm a complete noob but am slowly but surely learning</p>
  
  <p><strong>My Timer</strong></p>
  
  <pre><code>final Timer t = new Timer();
      t.schedule(new TimerTask() {
          public void run() {
              d.dismiss();  //MY DIALOG WINDOW
              t.cancel();
          }
      }, 7000);   
  </code></pre>
  
  <p>this is one i have tried to get to work but think i have done more damage then good with it</p>
  
  <pre><code>isRunning = false;
      // handler for the background updating
      final Handler handler = new Handler() {
          public void handleMessage(Message msg) {
              total = total - 1;
              String perc = String.valueOf(total).toString();
              a.setText(perc + " SECONDS  until close");
              bar.incrementProgressBy(25);
          }
      };
  
      super.onStart();
      // reset the bar to the default value of 0
      bar.setProgress(0);
      // create a thread for updating the progress bar
      Thread background = new Thread(new Runnable() {
          public void run() {
              try {
                  for (int i = 4; i &lt; 20 &amp;&amp; isRunning; i++) {
                      // wait 1000ms between each update
                      Thread.sleep(1000);
                      handler.sendMessage(handler.obtainMessage());
                  }
              } catch (Throwable t) {
              }
          }
      });
      isRunning = true;
      // start the background thread
      background.start();
  </code></pre>
  
  <p>hoping someone might be able to shed some light on this for me,, as always sorry for the short generic question, just looking to find out how to load progress bar with timer</p>
  
  <p>tahnks again for any and all help</p>