Reputation: 285
I am using Async Task to perform some operations in my database. During the operation, I'm showing a progress dialog and when it operations are finish I want to dismiss it but it doesn't work.
private ProgressDialog progressDialog;
private void showProgressDialog(String title, String message)
{
progressDialog = new ProgressDialog(this);
progressDialog.setTitle(title); //title
progressDialog.setMessage(message); // message
progressDialog.setCancelable(true);
progressDialog.show();
}
private class InsertFoodAsyncTask extends AsyncTask<Void, Integer, String>{
@Override
protected String doInBackground(Void... arg0){
InsertFood p = new InsertFood(Food.this,mBDD);
p.InsertFood();
return "Executed";
}
@Override
protected void onPreExecute() {
showProgressDialog("Please wait...", "Your message");
}
@Override
protected void onPostExecute(String result) {
if(progressDialog != null && progressDialog.isShowing())
{
progressDialog.dismiss();
}
}
}
Can you help me ? Thanks a lot !
Upvotes: 0
Views: 1904
Reputation: 11
Try it,
replace:
progressDialog.show();
for:
progressDialog = progressDialog.show();
Upvotes: 1
Reputation: 567
It seems all correct in your code. onPostExecute()
already make it run on ui thread. But still try to check with this also.
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if(progressDialog != null && progressDialog.isShowing())
{
progressDialog.dismiss();
}
}
});
Upvotes: 0