title: Android - How to show ProgressBar with background image onPreExecute() method of Asynchtask
body: <p>I am new on android. I am using XML parsing for my app and how can show an Background image and on top it a ProgessBar when click on my app and it hold the screen till my data will not come. I am exactly make my app like BBC News android app</p>
  
  <pre><code>AsyncTask&lt;Void, Void, Drawable&gt; downloader = new AsyncTask&lt;Void, Void, Drawable&gt;() {
  
      @Override
      protected Drawable doInBackground(Void... params) {
          AndroidHttpClient client = AndroidHttpClient.newInstance(context.getPackageName());
          try {
              HttpGet get = new HttpGet(url);
              final HttpParams httpParams = new BasicHttpParams();
              HttpClientParams.setRedirecting(httpParams, true);
              get.setParams(httpParams);
              HttpResponse resp = client.execute(get);
              int status = resp.getStatusLine().getStatusCode();
              if(status != HttpURLConnection.HTTP_OK){
                  //Log.i(LOGTAG, "Couldn't download image from Server: " + url + " Reason: " + resp.getStatusLine().getReasonPhrase() + " / " + status);
                  return null;
              }
              HttpEntity entity = resp.getEntity();
              //Log.i(LOGTAG, url + " Image Content Length: " + entity.getContentLength());
              InputStream is = entity.getContent();
              FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);
              copyStream(is, fos);
              fos.close();
              is.close();
              FileInputStream  fis = context.openFileInput(filename);
              return loadDrawableFromStream(context, fis);
          }
          catch (Exception ex) {
              //Log.e(LOGTAG, "Exception during Image download of " + url, ex);
              return null;
          }
          finally {
              client.close();
          }
      }
  
      @Override
      protected void onPostExecute(Drawable result) {
          if (result == null)
              result = defaultDrawable;
          mPendingDownloads.remove(url);
          cache.put(url, result);
          for (ImageView iv: downloads) {
              // validate the url it is waiting for
              String pendingUrl = mPendingViews.get(iv);
              if (!url.equals(pendingUrl)) {
                  //Log.i(LOGTAG, "Ignoring out of date request to update view for " + url);
                  continue;
              }
              mPendingViews.remove(iv);
              if (result != null) {
                  final Drawable newImage = result;
  
                  Drawable newSize=resize(newImage);
  
  
                  final ImageView imageView = iv;
  
                  imageView.setImageDrawable(newSize);
              }
          }
      }
  
      private BitmapDrawable resize(Drawable newImage) {
          // TODO Auto-generated method stub
  
          Bitmap d = ((BitmapDrawable)newImage).getBitmap();
          Bitmap bitmapOrig = Bitmap.createScaledBitmap(d, 75, 75, false);
          return new BitmapDrawable(bitmapOrig);                                              
      }
  };
  downloader.execute();
  }
  
  private static Hashtable&lt;ImageView, String&gt; mPendingViews = new Hashtable&lt;ImageView, String&gt;();
  private static Hashtable&lt;String, ArrayList&lt;ImageView&gt;&gt; mPendingDownloads = new Hashtable&lt;String, ArrayList&lt;ImageView&gt;&gt;();
  }
  </code></pre>