title: Having problems trying to set an adapter inside an AsyncTask
body: <p>I  need to retrieve some huge data from one database when an activity is started. To prevent a user with a frozen window, I decided to run a ProgressDialog while data is being processed.</p>
  
  <p>From OnCreate I call my initDb Class:</p>
  
  <p>new initDb().execute();</p>
  
  <p>And then to do this I have one class inside my activity's class:</p>
  
  <pre><code>public class initDb extends AsyncTask&lt;Void, Void, Void&gt; {
  
      ProgressDialog mDialog = new ProgressDialog(ClientsReg.this);
  
      @Override
      protected void onPreExecute() {
          mDialog.setMessage("Please wait...");
          mDialog.show();
      }
  
  
      @Override
      protected Void doInBackground(Void... voids) {
  
          opendb();
          listCities();
      return null;
  
  
      }
  
  @Override
      protected void onPostExecute(Void unused) {
          // Pass the result data back to the main activity
          mDialog.dismiss();
      }
  </code></pre>
  
  <p>} </p>
  
  <p>The real problem happens while setting the adapter:</p>
  
  <pre><code>private void listCities() {
  
  
        mRedrawHandler.sleep(100000);
  
  
          c = db.executeSQL("SELECT * FROM RegDB WHERE Reg_Type = 1 AND cad_uzkow = 0 ORDER BY _id DESC");
  
          //add some list items
          ArrayList&lt;String&gt; finalList = new ArrayList&lt;String&gt;();
  
          c.moveToFirst();
  
  
          while (!c.isAfterLast()){
  
              finalList.add(c.getString(0) + ")"+ c.getString(5));            
              c.moveToNext();
          }
  
  
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
                  R.layout.row, R.id.itemShow, finalList);
          sp.setAdapter(adapter);
  
  
      }
  </code></pre>
  
  <p>It always happen to crash on sp.setAdapter(adapter);</p>
  
  <p>Any ideas?</p>
  
  <p>Thank you!</p>