title: Pass a Message From Thread to Update UI
body: <p>Ive created a new thread for a file browser. The thread reads the contents of a directory. What I want to do is update the UI thread to draw a graphical representation of the files and folders. I know I can't update the UI from within a new thread so what I want to do is:</p>
  
  <p>whilst the file scanning thread iterates through a directories files and folders pass a file path string back to the UI thread. The handler in the UI thread then draws the graphical representation of the file passed back.</p>
  
  <pre><code>public class New_Project extends Activity implements Runnable {
  
      private Handler handler = new Handler() {
          @Override
          public void handleMessage(Message msg) {
              Log.d("New Thread","Proccess Complete.");
              Intent intent = new Intent();
              setResult(RESULT_OK, intent);
              finish();
          }
      };
  
  
      public void fileScanner(){
          //if (!XMLEFunctions.canReadExternal(this)) return;
          pd = ProgressDialog.show(this, "Reading Directory.",
                  "Please Wait...", true, false);
  
          Log.d("New Thread","Called");
          Thread thread = new Thread(this);
          thread.start();
      }
  
  
      public void run() {
          Log.d("New Thread","Reading Files");
          getFiles();
          handler.sendEmptyMessage(0);
      }
  
  
      public void getFiles() {
          for (int i=0;i&lt;=allFiles.length-1;i++){
              //I WANT TO PASS THE FILE PATH BACK TU A HANDLER IN THE UI
              //SO IT CAN BE DRAWN.
              **passFilePathBackToBeDrawn(allFiles[i].toString());**
          } 
      }
  
  }
  </code></pre>