How to use AsyncTask to show a ProgressDialog while doing background work in Android? [duplicate]

Place your ProgressDialog in onPreExecute, sample code below:

private ProgressDialog pdia;

@Override
protected void onPreExecute(){ 
   super.onPreExecute();
        pdia = new ProgressDialog(yourContext);
        pdia.setMessage("Loading...");
        pdia.show();    
}

@Override
protected void onPostExecute(String result){
   super.onPostExecute(result);
        pdia.dismiss();
}

and in your onClickListener, just put this line inside:

new EfetuaLogin().execute(null, null , null);

Leave a Comment