title: Android - progressdialog not displaying in AsyncTask
body: <p>I have an android app that I am having trouble with.</p>
  
  <p>Basically the <code>ProgressDialog</code> is not showing at all. I believe this to be a threading issue of some sort but I don't know how to fix it.</p>
  
  <p>I am using <code>ActionBarSherlock</code> with some <code>Fragments</code>. I am also using the new Android <code>DrawerLayout</code> where I have my options on the drawer, which replace a fragment when clicked.</p>
  
  <p>On first load of my app, I want to check the database to see if the inital data has been downloaded. If not, then I go off and begin an <code>AsyncTask</code> to download the data. This SHOULD have a  <code>ProgressDialog</code> display during this, but it doesnt.</p>
  
  <p>Can someone see where I am going wrong? Thanks.</p>
  
  <p><strong>MainScreen</strong> - The default landing page/fragment when the app opens</p>
  
  <pre><code>public class MainScreen extends SherlockFragment {
      public static final String TAG = "MainScreen";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.activity_main, container, false);
          setHasOptionsMenu(false);
  
          ImageView imgLogo = (ImageView) rootView.findViewById(R.id.imgMainScreen);
          imgLogo.setOnClickListener(new ButtonHandler(getActivity()));
  
          checkDatabase();
          return rootView;
      }
  
      private void checkDatabase() {
          //Ensure there is data in the database
          DBHelper db = new DBHelper(this.getSherlockActivity());
          db.checkDatabase();
      }
  ...
  }
  </code></pre>
  
  <p><strong>DBHelper.checkDatabase()</strong> - The method that initiates the download</p>
  
  <pre><code>public void checkDatabase() {
      if (isEmpty()) {
          //Connect to net and download data
          NetworkManager nm = new NetworkManager(activity);
          if (!nm.downloadData()) {
              Toast.makeText(activity, R.string.internetCheck, Toast.LENGTH_SHORT).show();
          }
      }
  }
  </code></pre>
  
  <p>and finally
  <strong>NetworkManager.downloadData()</strong> - The method that kicks off the <code>AsyncTask</code>:</p>
  
  <pre><code>   public boolean downloadData() {
          try {
              return new HttpConnection(activity).execute().get();
          } catch (InterruptedException e) {
              e.printStackTrace();
          } catch (ExecutionException e) {
              e.printStackTrace();
          }
          return false;
      }
  
      public class HttpConnection extends AsyncTask&lt;Void, Void, Boolean&gt; {
          private ProgressDialog progressDialog;
          private Activity m_activity;
  
          protected HttpConnection(Activity activity) {
              m_activity = activity;
          }
  
          @Override
          protected void onPreExecute() {
              progressDialog = new ProgressDialog(m_activity);
              progressDialog.setMessage("Wait ...");
              progressDialog.setCancelable(false);
              progressDialog.setMax(100);
              progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
              progressDialog.show();
  
              super.onPreExecute();
          }
  
          @Override
          protected Boolean doInBackground(Void... params) {
              String[] types = new String[]{"type1", "type2", "type3", "type4", };
              StringBuilder sb = new StringBuilder();
  
              for(String type : types) {
                  sb = new StringBuilder();
                  if(DBHelper.TYPE4_TABLE.equals(type)) {
                      InputStream is = activity.getResources().openRawResource(R.raw.dbdata);
                      BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                      try {
                          sb.append(reader.readLine());
                      } catch (IOException e) {
                          Toast.makeText(activity.getApplicationContext(), "Error retriveving data", Toast.LENGTH_SHORT).show();
                          Log.e(Constants.TAG, "Error reading data");
                          e.printStackTrace();
                      }
                  } else {
                      sb = fetchURLData(Constants.ALL_URL+type);
                  }
                  cleanDataAndStore(sb, type);
              }
  
              return true;
          }
  
          @Override
          protected void onPostExecute(Boolean result){
                progressDialog.hide();
          }
      }
  </code></pre>
  
  <p>Using the above code, all I get is a white screen as the app tries to load, and sometimes an ANR. When the download is done, the fragment loads. So it works fine except for the missing <code>ProgressDialog</code>.</p>
  
  <p>PS, Notice I'm setting the <code>activity</code> in each constructor.</p>
  
  <p>Thanks.</p>