title: java.lang.IllegalStateException when adding a View in debug mode
body: <p>I am using the AsyncTask and I am getting the following error in the onProgressUpdate method:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: The
    specified child already has a parent.
    You must call removeView() on the
    child's parent first. at
    android.view.ViewGroup.addViewInner(ViewGroup.java:1970)
    at
    android.view.ViewGroup.addView(ViewGroup.java:1865)
    at
    android.widget.TableLayout.addView(TableLayout.java:418)</p>
  </blockquote>
  
  <p>I know what this error means and how to resolve it. What I do not understand is why I am getting this error ONLY in debug mode. Adding a Thread.Sleep(1000) to the doInBackground method practically negates the issue, but I cannot add that for obvious performance reasons. 
  Here is the gist of what is happening in my AsyncTask:</p>
  
  <pre><code> protected Void doInBackground(Void... params) {
  
      row1 = TableVisuals.createRow(context, flag);
      tv1 = TableVisuals.getTextView(context, Info[0]);
      row2 = TableVisuals.createRow(context, flag);
      tv2 = TableVisuals.getTextView(context, Info[1]);
      publishProgress(i,0);
  
  }
  
  protected void onProgressUpdate(Integer... value) {
  
  table.addView(row1);
  row1.addView(tv1, 0, span);
  table.addView(row2);
  row2.addView(tv2, 0, span);
  
  dialog.setProgress(value[0]);
  
  }
  </code></pre>
  
  <p>Keep in mind, the IllegalStateException does not happen in any one part of the above code. It is inconsistent in places, but almost always occurs. I wish there was a way for the background thread to wait for the UI thread other than Thread.Sleep() because it appears that it is adding views too fast in some cases.</p>