title: Image downloading via multithreading not working in Android
body: <p>I have to download an image from a url and then show the downloaded image in a imageview on the UI. 
  For this i am using the code mentioned below:</p>
  
  <pre><code>public class ShowUIData extends AsyncTask&lt;Void, Void, Void&gt; {
      String productvalues[];
      Drawable productimagebitmap;
  
      @Override
      protected Void doInBackground(Void... params) {
          productvalues = hb.getProductDetailsWithJson(id + 1);
          if (productvalues != null) {
              productimagebitmap = getImage(productvalues[3]);
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          super.onPostExecute(result);
          if (productvalues != null) {
              // Set the values obtained from the database.
              // Check if image returned from URL is not null.
              if (productimagebitmap != null) {
                  ImageView productimage = (ImageView) findViewById(R.id.productimage);
                  productimage.setImageDrawable(productimagebitmap);
              }
          }
          dismissDialog();
      }
  
      // Download image from URL obtained for database.
      private Drawable getImage(String address) {
          try {
              Log.i("product details", "starting image download");
              URL url = new URL(address);
              URLConnection conn = url.openConnection();
              conn.connect();
              InputStream is = conn.getInputStream();
              Drawable d = Drawable.createFromStream(is, "src name");
              is.close();
              return d;
          } catch (Exception e) {
              Log.i("the url", address);
              e.printStackTrace();
              return getApplicationContext().getResources().getDrawable(
                      R.drawable.noimage);
          }
      }
  </code></pre>
  
  <p>A valid URL is being passed to the getImage function and no exception is being thrown , still the image is not being set on the imageview. When i debug my application, then the image is setting properly.
  I believe i need to put a blocking call until the image is download and then call image.setImageDrawable.</p>
  
  <p>What is the problem occuring over here. I am not able to figure out why i am not able to load any images and why only when i debug , i see an image?</p>
  
  <p>thank you in advance.</p>