I get the leaked windows error when I try to finish my activity.
I looked at a lot of similar questions about this and the answer was to use dismiss() instead of hide(), or dismiss the dialog before calling finish().
I call dismiss() then call finish() why am I getting a leak?
Here is my ProgressDialog code that is in a class extending AsyncTask
public Background(Context c){
context = c; //the activity's context
dialog = new ProgressDialog(c);
}
protected void onPreExecute(){
dialog.show();
}
protected String doInBackground(String... urls) {
//do http request
return "";
}
protected void onPostExecute(String result) {
dialog.dismiss();
if(request == LOGOUT_REQUEST)
finish();
else{
getResults(document);
}
}
It worked before, but I believe my code was wrong. I was starting a new activity back to the old activity, instead of just calling finish, which I believe is the right thing to do.
You are dismissing the dialog in the
onPostExecutemethod. That method won’t run unless theAsyncTaskhas completed. Are you only getting the error when you exit the app with the back button? If so, you should also make sure the dialog is dismissed in theonDestroyof your Activity.