title: ProgressDialog shows black screen
body: <p>I have read some related questions but they all suggest I use a handler and threads which I am using, yet I still get a black out when running this code, the progress bar cannot be seen moving and after a few seconds the screen goes black. However the process finished after that by a short while.</p>
  
  <p>Code :</p>
  
  <pre><code>public void onRunButtonClicked(View view) throws IOException
  {
      // prepare for a progress bar dialog
      progressBarStatus = 0;
      progressBar = new ProgressDialog(view.getContext());
      progressBar.setCancelable(true);
      progressBar.setMessage("Updating...");
      progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
      progressBar.setProgress(0);
      progressBar.setMax(97);
      progressBar.show();
  
      // bulk insert books
      bulkInsertBooks(this.getApplicationContext());
  }
  
  private void bulkInsertBooks(final Context context) throws IOException
  {
      // setup progressbar
      progressBar.setMax(5000);
  
      new Thread(new Runnable()
      {
          public void run()
          {
              // delete existing rows
              db.execSQL("DELETE FROM Book");
  
              // load csv from assets
              InputStream is = null;
              try
              {
                  is = context.getAssets().open("books.dat");
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
  
              BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  
              // now insert into db
              String sql = "INSERT INTO Book VALUES (?,?,?,?,?,?);";
              SQLiteStatement statement = db.compileStatement(sql);
              db.beginTransaction();
  
              String line;
              try
              {
                  while ((line = reader.readLine()) != null)
                  {
                      String[] RowData = line.split("\\|");
                      statement.clearBindings();
                      statement.bindString(1, RowData[0]);
                      statement.bindString(2, RowData[1]);
                      statement.bindString(3, RowData[2]);
                      statement.bindString(4, RowData[3]);
                      statement.bindString(5, RowData[4]);
                      statement.bindString(6, RowData[5]);
                      statement.execute();
  
                      // Update the progress bar in every iteration
                      progressBarHandler.post(new Runnable()
                      {
                          public void run()
                          {
                              progressBar.setProgress(progressBarStatus++);
                          }
                      });
                  }
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
  
              // finish
              db.setTransactionSuccessful();
              db.endTransaction();
              if (is != null)
              {
                  try
                  {
                      is.close();
                  }
                  catch (IOException e)
                  {
                      e.printStackTrace();
                  }
              }
          }
      }).start();
  }
  </code></pre>