android View not attached to window manager

后端 未结 13 2239
臣服心动
臣服心动 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 10:57

    Another option is not to start the async task until the dialog is attached to the window by overriding onAttachedToWindow() on the dialog, that way it is always dismissible.

    0 讨论(0)
  • 2020-11-27 10:57

    Or Simply you Can add

    protected void onPreExecute() {
        mDialog = ProgressDialog.show(mContext, "", "Saving changes...", true, false);
    }
    

    which will make the ProgressDialog to not cancel-able

    0 讨论(0)
  • 2020-11-27 11:00

    I added the following to the manifest for that activity

    android:configChanges="keyboardHidden|orientation|screenLayout"
    
    0 讨论(0)
  • 2020-11-27 11:02

    For question 1):

    Considering that the error message doesn't seem to say which line of your code is causing the trouble, you can track it down by using breakpoints. Breakpoints pause the execution of the program when the program gets to specific lines of code. By adding breakpoints to critical locations, you can determine which line of code causes the crash. For example, if your program is crashing at a setContentView() line, you could put a breakpoint there. When the program runs, it will pause before running that line. If then resuming causes the program to crash before reaching the next breakpoint, you then know that the line that killed the program was between the two breakpoints.

    Adding breakpoints is easy if you're using Eclipse. Right click in the margin just to the left of your code and select "Toggle breakpoint". You then need to run your application in debug mode, the button that looks like a green insect next to the normal run button. When the program hits a breakpoint, Eclipse will switch to the debug perspective and show you the line it is waiting at. To start the program running again, look for the 'Resume' button, which looks like a normal 'Play' but with a vertical bar to the left of the triangle.

    You can also fill your application with Log.d("My application", "Some information here that tells you where the log line is"), which then posts messages in Eclipse's LogCat window. If you can't find that window, open it up with Window -> Show View -> Other... -> Android -> LogCat.

    Hope that helps!

    0 讨论(0)
  • 2020-11-27 11:02

    when you declare activity in the manifest you need android:configChanges="orientation"

    example:

    <activity android:theme="@android:style/Theme.Light.NoTitleBar" android:configChanges="orientation"  android:label="traducción" android:name=".PantallaTraductorAppActivity"></activity>
    
    0 讨论(0)
  • 2020-11-27 11:03

    If you have an Activity object hanging around, you can use the isDestroyed() method:

    Activity activity;
    
    // ...
    
    if (!activity.isDestroyed()) {
        // ...
    }
    

    This is nice if you have a non-anonymous AsyncTask subclass that you use in various places.

    0 讨论(0)
提交回复
热议问题