title: How to get intent data from a runnable back to a calling intent
body: <p>I need to start a thread that downloads an image from the web, then return the location of that image on external drive via an intent to the calling activity.  In this example I am starting in MainActivity, creating an intent that calls the DownloadImage class where the runnable and thread are located.  That runnable in turn calls a utility class to do all of the work off of the UI thread.</p>
  
  <p>Where I am stuck is how to get that work result back to MainActivity.  When I run this code I get a null for my intent data.  Can anyone tell me where the problem is?</p>
  
  <pre><code>---------------------------------------------------------
  MainActivity.class 
  
  ...      
  
  Uri urlData = Uri.parse("http://www.testUrl.com/image.png");
  
      Intent downloadIntent = new Intent(this, DownloadImage.class);
      downloadIntent.putExtra("imageUri", urlData);
  
      startActivityForResult(downloadIntent, DOWNLOAD_IMAGE_REQUEST);
  
      @Override
  protected void onActivityResult(int requestCode,
                                  int resultCode,
                                  Intent data) {
      if (resultCode == RESULT_OK) {
          if (requestCode == DOWNLOAD_IMAGE_REQUEST) {
              Intent galleryIntent = makeGalleryIntent(data.toString());
  
              startActivity(galleryIntent);
          }
      }
      else if (resultCode != RESULT_OK || requestCode != DOWNLOAD_IMAGE_REQUEST) {
  
          Toast.makeText(this,
                  "Activity did not complete correctly.",
                  Toast.LENGTH_SHORT).show();
      }
  }
  
  
  ---------------------------------------------------------
  DownloadImage.class
  
  ...
  
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
          final Uri data = getIntent().getData();
  
          Runnable downloadRunnable = new Runnable() {
  
             @Override
             public void run() {
  
             Intent i = new Intent(DownloadImage.this, MainActivity.class)                
             i.putExtra("urlData", DownloadUtils.downloadImage(DownloadImageActivity.this, data));
          } 
  // downloadImage takes in a Uri object and context to create a location on disk for the result.  returns a uri object.          
          setResult(RESULT_OK, i);
          };
  
          thread = new Thread (downloadRunnable);
          thread.start();
          finish();
  
  }
  </code></pre>