My Problem is similar to this one:
Error on dismissing ProgressDialog in AsyncTask
I have an AsyncTask that creates a dialog in onPreExecute like this:
dialog = ProgressDialog.show(activity, "login", "logging in, one moment please");
And dismisses the dialog in onPostExecute like this:
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
Still, i get error reports from users on the line where i do diolog.dismiss() with the message: java.lang.IllegalArgumentException: View not attached to window manager
The most common root-cause is - or so i've read - when a user switches orientation (from portrait to landscape or vice versa). My app however is forced to portrait mode, so this can not be the cause. (i've double checked this to make sure it really is not possible)
The reporter of the before mentioned post solved it in the end (and i've read this solution elsewhere too) by creating an inner class for the AsyncTask in the activity class and working with onCreateDialog from the activity class and calling showDialog from the AsyncTask. (read his post if you don't understand this) I've begun trying to implement that, but it seems that showDialog is deprected: so this is not a solution for me.
The last solution i've found is by simply catching the Exception. I had thought of that myself too, but only as a last resort. I prefer to understand what really goes wrong and anticipate on that instead of simply catching the exception and not knowing what is going on.