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);
}
}
}
You are trying to show a dialog window after you are exit from your screen.
Use this in onStop --->
@Override
protected void onStop() {
super.onStop();
if (pDialog != null) {
pDialog.dismiss();
pDialog = null;
}
}
You have to dismiss the dialog before activity get destroyed
@Override
protected void onDestroy() {
super.onDestroy();
if(pDialog!=null && pDialog.isShowing())
pDialog.dismiss();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With