I have a problem with AsyncTask
.
I update a list of object by calling a webService. During this time, i want to display a ProgressDialog
. Then when the list is fully updated, i want the dialog the close and the AsyncTask too.
The problem is that the UIThread doesn't wait the AsyncTask
to finish. I see that the get()
method can work for me, but with it, the UIThread is just blocked, and the dialog just doesn't show.
I would like to know how i can manage to wait the task to finish while displaying a ProgressDialog.
Here is my AsyncTask Class :
public class MyAsyncTask extends AsyncTask<Integer, Void, Boolean>{
private ProgressDialog pd;
private String m_sShelfCode;
private String m_sFamiliyCode;
public MyAsyncTask(String shelfCode, String familyCode) {
this.m_sShelfCode = shelfCode;
this.m_sFamiliyCode = familyCode;
}
@Override
protected void onPreExecute() {
AppManager app = AppManager.getInstance();
LayoutInflater inflater = (LayoutInflater)app.m_AppContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout rl = (RelativeLayout)inflater.inflate(R.layout.progress_dialog, null, false);
pd = new ProgressDialog(app.m_AppContext);
pd.requestWindowFeature(Window.FEATURE_NO_TITLE);
pd.setCancelable(false);
pd.show();
pd.setContentView(rl);
}
@Override
protected Boolean doInBackground(Integer... params) {
Log.d("DO IN BACKGROUND","param[0]="+params[0]);
switch (params[0]) {
case AppManager.SHELF_LIST:
//Calling WebService
SoapShelf s = new SoapShelf();
try {
ArticleListFragment.m_ShelfList = s.getShelfList();
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (XmlPullParserException e) {
e.printStackTrace();
return false;
}
break;
case AppManager.FAMILY_LIST:
// set family list
break;
case AppManager.ARTICLE_LIST:
// set article list
break;
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
pd.dismiss();
if (result == false)
;// error dialog
}
}
I call this in my ArticleListFragment here
public void getItemList(int listType) {
switch (listType) {
case AppManager.SHELF_LIST:
new MyAsyncTask(null, null).execute(new Integer[]{AppManager.SHELF_LIST});
Thanks in advance