Reputation: 2743
Ok so I am trying to get a progress dialog to show when data is being downloaded from the internet and being applied to the UI. My asynctask is working fine and it runs though all the steps, but it never shows the dialog ever. I don't know what I have done wrong here and I pretty much hit the wall. I even tried to put the async task into the new runnable thread and run it like that, that also did not show the dialog. I am calling the async task like this
new runningMan().execute();
Here is the code that I am trying to run.
private class runningMan extends AsyncTask<Void, Void, Integer>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
Log.d("Runningman: ", "Started running");
//this method will be running on UI thread
progress = ProgressDialog.show(PromotionMain.this, "Loading", "PleaseWait", true);
}
@Override
protected Integer doInBackground(Void... params) {
//parse the JSON string
JSONParser jp = new JSONParser();
try {
Log.d(username , password);
jp.parsesData(promos, myJson, pictureArray, pathArray, labelArray);
Log.d("Runningman: ", "Finished parsing");
} catch (IOException e) {
e.printStackTrace();
}
return 1;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
ArrayList<ListItem> listData = getListData();
fillListView(listData);
Log.d("Runningman: ", "Finished runing");
//this method will be running on UI thread
progress.dismiss();
}
}
Thank you for any help with this.
Upvotes: 2
Views: 2976
Reputation: 1820
Call "super.onPreExecute();" and "super.onPostExecute(result);" after your code for progress dialog. Or better, get rid of them (if you don't have reasons for calling them).
Use the following code:
private class runningMan extends AsyncTask<Void, Void, Integer>
{
@Override
protected void onPreExecute() {
Log.d("Runningman: ", "Started running");
//this method will be running on UI thread
progress = ProgressDialog.show(PromotionMain.this, "Loading", "PleaseWait", true);
super.onPreExecute();
}
@Override
protected Integer doInBackground(Void... params) {
//parse the JSON string
JSONParser jp = new JSONParser();
try {
Log.d(username , password);
jp.parsesData(promos, myJson, pictureArray, pathArray, labelArray);
Log.d("Runningman: ", "Finished parsing");
} catch (IOException e) {
e.printStackTrace();
}
return 1;
}
@Override
protected void onPostExecute(Integer result) {
ArrayList<ListItem> listData = getListData();
fillListView(listData);
Log.d("Runningman: ", "Finished runing");
//this method will be running on UI thread
progress.dismiss();
super.onPostExecute(result);
}
}
Upvotes: 2