android View not attached to window manager

后端 未结 13 2234
臣服心动
臣服心动 2020-11-27 10:29

I am having some of the following exceptions:

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findV         


        
相关标签:
13条回答
  • 2020-11-27 11:07

    I had this issue where on a screen orientation change, the activity finished before the AsyncTask with the progress dialog completed. I seemed to resolve this by setting the dialog to null onPause() and then checking this in the AsyncTask before dismissing.

    @Override
    public void onPause() {
        super.onPause();
    
        if ((mDialog != null) && mDialog.isShowing())
            mDialog.dismiss();
        mDialog = null;
    }
    

    ... in my AsyncTask:

    protected void onPreExecute() {
        mDialog = ProgressDialog.show(mContext, "", "Saving changes...",
                true);
    }
    
    protected void onPostExecute(Object result) {
       if ((mDialog != null) && mDialog.isShowing()) { 
            mDialog.dismiss();
       }
    }
    
    0 讨论(0)
提交回复
热议问题