You are leaking the dialog. You need to call pDialog.dismiss();
in the onPostExecute() method of the async task. You should also put…
if(pDialog != null)
pDialog.dismiss();
in your onPause() method of the activity on the main thread. This will make sure the window is not leaked, even if your application loses the foreground while doing some background execution. You should have something like this…
public class Login extends Activity implements View.OnClickListener{
ProgressDialog pd;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.login);
pd = null;
}
@Override
public void onPause(){
super.onPause();
if(pd != null)
pd.dismiss();
}
public void onClick(View v){
new SendTask().execute("");
}
/*
No networking allowed on the main thread.
*/
private class SendTask extends AsyncTask<String,String,String>{
int result;
@Override
protected void onPreExecute(){
pd = ProgressDialog.show(Login.this,"","Retrieving Inbox...", true,false);
}
@Override
protected String doInBackground(String...strings){
//do networking here
result = account.prepare();
return null;
}
@Override
protected void onPostExecute(String unused){
//check result
pd.dismiss();
Intent intent = new Intent(Login.this,NextActivity.class);
finish();
startActivity(intent);
}
}
}