In my activity there is a async task which connects to the internet and saves data in my database. when I change the orientation while this task is running I'll get an exception:
07-27 16:01:45.956 10173-10173/de.MayerhoferSimon.Vertretungsplan E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:668)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:364)
at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:163)
at android.app.Dialog.dismissDialog(Dialog.java:347)
at android.app.Dialog.dismiss(Dialog.java:330)
at de.MayerhoferSimon.Vertretungsplan.MainActivity$1.onPostExecute(MainActivity.java:129)
at de.MayerhoferSimon.Vertretungsplan.MainActivity$1.onPostExecute(MainActivity.java:90)
at android.os.AsyncTask.finish(AsyncTask.java:631)
so this is what my AsyncTask is look like:
@Override
protected void onPreExecute() {
isRefreshing = true;
this.dialog.setMessage("Lädt Daten...");
this.dialog.show();
}
@Override
protected void onPostExecute(String successful) {
if (!isFinishing()) {
if (successful.equals("succeed")) {
Toast toast = Toast.makeText(context, R.string.toast_refresh_succeed, Toast.LENGTH_LONG);
toast.show();
}
else if (successful.equals("failed")) {
Toast toast = Toast.makeText(context, R.string.toast_refresh_failed, Toast.LENGTH_LONG);
toast.show();
}
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
}
}
What I now want is to set a delay on the orientationchange, that this will not happen again and the orientation will change only when the AsyncTask finished.