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 !