문제

I keep getting this error but I am not sure why

java.lang.IllegalArgumentException: View not attached to window manager
        at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:587)
        at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:324)
        at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:151)
        at android.app.Dialog.dismissDialog(Dialog.java:328)
        at android.app.Dialog$1.run(Dialog.java:119)
        at android.app.Dialog.dismiss(Dialog.java:313)

And it happens in this code

    @Override
    protected void onPostExecute(Void result) {
        if(!isFinishing() && dialog.isShowing()){
            dialog.dismiss();  <-------- HERE IT HAPPENS
        }
   }

Any idea why? I am making sure the activity is not finishing and the dialog is showing before dismissal!

도움이 되었습니까?

해결책

This normally happens when the Activity might have finished or in pause state before the AsyncTask is complete. onPause of the Activity set the dialog to null or dismiss it

@Override
protected void onPostExecute(Void result) {
    if(!isPaused && dialog.isShowing()){
        dialog.dismiss();  <-------- HERE IT HAPPENS
    }
}
boolean isPaused;
@Override
protected void onPause() {
    super.onPause();
    isPaused = true;
}
@Override
protected void onResume() {
    super.onResume();
    isPaused = false;
    if(dialog.isShowing() && (asyncFinishedCheck)){
        //Dismiss code goes here
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top