title: Android SDK AsyncTask doInBackground not running (subclass)
body: <p><strong>As of 15/2/2012 I have yet to find a good explanation to nor a reason why this does not work. The closest to a solution is to use the traditional <a href="https://stackoverflow.com/a/4085140/1107464/">Thread</a> approach, but then why include a class that does not (seem to) work in the Android SDK?</strong></p>
  
  <p>Evenin' SO!</p>
  
  <p>I have an AsyncTask subclass:</p>
  
  <pre><code>// ParseListener had a callback which was called when an item was parsed in a
  // RSS-xml, but as stated further down it is not used at all right now.
  private class xmlAsync extends AsyncTask&lt;String, RSSItem, Void&gt; implements ParseListener
  </code></pre>
  
  <p>That is executed like this:</p>
  
  <pre><code>xmlAsync xmlThread = new xmlAsync();
  
  xmlThread.execute("http://www.nothing.com");
  </code></pre>
  
  <p>Now this subclass has run into a little error. Previously it did some xml-parsing, but when I noticed that it's <strong>doInBackground()</strong> wasn't called I stripped it down, line by line, finally ending up with just this:</p>
  
  <pre><code>@Override
  protected Void doInBackground(String... params) 
  {
      Log.v(TAG, "doInBackground");
          return null;
  }
  </code></pre>
  
  <p>Which, for some reason, logged nothing. However, I added this:</p>
  
  <pre><code>@Override
  protected void onPreExecute() 
  {
          Log.v(TAG, "onPreExecute");
          super.onPreExecute();
  }
  </code></pre>
  
  <p>And that line is indeed logged when executing the thread. <strong><em>So somehow onPreExecute() is called but not doInBackground()</em></strong>. I have another AsyncTask running in the background at the same time which works just fine.</p>
  
  <p>I'm currently running the app on an emulator, SDK Version 15, Eclipse, Mac OS X 10.7.2, close to the North Pole.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>@Override
      protected void onProgressUpdate(RSSItem... values) {
  
          if(values[0] == null)
          {
                              // activity function which merely creates a dialog
              showInputError();
          }
          else
          {
  
              Log.v(TAG, "adding "+values[0].toString());
              _tableManager.addRSSItem(values[0]);
          }
  
  
          super.onProgressUpdate(values);
      }
  </code></pre>
  
  <p>_tableManager.addRSSItem() more or less adds a row to a SQLiteDatabase, initialized with the activity's context. publishProgress() is called by the Interface ParseListener's callback. However, since I don't even do anything except log.v in doInBackground() I first found this unnecessary to even bring up.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Alright, just to be perfectly clear, this is the other AsyncTask, executing in the same activity and working perfectly fine.</p>
  
  <pre><code>private class dbAsync extends AsyncTask&lt;Void, RSSItem, Void&gt;
  {
      Integer prevCount;
      boolean run;
  
      @Override
      protected void onPreExecute() {
          run = true;
          super.onPreExecute();
      }
  
      @Override
      protected Void doInBackground(Void... params) {
          // TODO Auto-generated method stub
          run = true;
          prevCount = 0;
  
          while(run)
          {
              ArrayList&lt;RSSItem&gt; items = _tableManager.getAllItems();
  
              if(items != null)
              {
                  if(items.size() &gt; prevCount)
                  {
                      Log.v("db Thread", "Found new item(s)!");
                      prevCount = items.size();
  
                      RSSItem[] itemsArray = new RSSItem[items.size()];
  
                      publishProgress(items.toArray(itemsArray));
                  }
              }               
  
              SystemClock.sleep(5000);
          }
  
          return null;
      }
  
      @Override
      protected void onProgressUpdate(RSSItem... values) {
  
          ArrayList&lt;RSSItem&gt; list = new ArrayList&lt;RSSItem&gt;();
  
          for(int i = 0; i &lt; values.length; i++)
          {
              list.add(i, values[i]);
          }
  
          setItemsAndUpdateList(list);
  
          super.onProgressUpdate(values);
      }
  
      @Override
      protected void onCancelled() {
          run = false;
  
          super.onCancelled();
      }
  }
  </code></pre>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>Sigh, sorry I'm bad at asking questions. But here is the initialization of the Tasks.</p>
  
  <pre><code>xmlAsync _xmlParseThread;
  dbAsync _dbLookup;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  _dbLookup = new dbAsync();
  _dbLookup.execute();
  
  _xmlParseThread = new xmlAsync();       
  _xmlParseThread.execute("http://www.nothing.com", null);
  }
  </code></pre>