Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ASync task ProgressDialog isn't showing until background thread finishes
    primarykey
    data
    text
    <p>I've got an Android activity which grabs an RSS feed from a URL, and uses the SAX parser to stick each item from the XML into an array. This all works fine but, as expected, takes a bit of time, so I want to use AsyncActivity to do it in the background. My code is as follows:</p> <pre><code>class AddTask extends AsyncTask&lt;Void, Item, Void&gt; { protected void onPreExecute() { pDialog = ProgressDialog.show(MyActivity.this,"Please wait...", "Retrieving data ...", true); } protected Void doInBackground(Void... unused) { items = parser.getItems(); for (Item it : items) { publishProgress(it); } return(null); } protected void onProgressUpdate(Item... item) { adapter.add(item[0]); } protected void onPostExecute(Void unused) { pDialog.dismiss(); } } </code></pre> <p>Which I call in <code>onCreate()</code> with</p> <pre><code>new AddTask().execute(); </code></pre> <p>The line <code>items = parser.getItems()</code> works fine - <code>items</code> being the arraylist containing each item from the XML. The problem I'm facing is that on starting the activity, the ProgressDialog which i create in <code>onPreExecute()</code> isn't displayed until <em>after</em> the <code>doInBackground()</code> method has finished. i.e. I get a black screen, a long pause, then a completely populated list with the items in. Why is this happening? Why isn't the UI drawing, the ProgressDialog showing, the parser getting the items and incrementally adding them to the list, then the ProgressDialog dismissing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload