1

I am building a tablet app in Android 3.0 that should always be displayed in landscape no matter what orientation the tablet is in. I pop up a dialog to the user on start up. When the tablet is locked in landscape, turned to portrait and unlocked, the app crashes. I have found that the issue is an IllegalStateException with a message "View not attached to window manager". I have added into the manifest in the application tag:

android:configChanges="orientation"

and added into the activity:

public void onConfigurationChange() {}

The error is thrown on Dialog.dismiss().

Let me know if you need any more info. Thanks in advance.

cren90
  • 1,367
  • 2
  • 17
  • 30
  • whats exactly the error? – waqaslam Mar 14 '12 at 22:10
  • paste your code for `public void onConfigurationChange()` – waqaslam Mar 14 '12 at 22:14
  • The onConfigurationChange method is empty as there should not be any change. – cren90 Mar 14 '12 at 22:45
  • The error occurs when calling dismiss on the dialog (the code for this is in onStart() and the error is "IllegalStateException" the message associated with it is "View not attached to window manager" as I stated in my question. – cren90 Mar 14 '12 at 22:47
  • It sounds like you have not initialized your dialog and you are getting a NullPointerException. Paste your logcat output. – MrZander Mar 14 '12 at 23:11

3 Answers3

3

i think your onConfigurationChange method shouldn't be empty. You should also call the super method in it. Write it like this:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    //your optional code
}
waqaslam
  • 67,549
  • 16
  • 165
  • 178
2

Try dismissing the dialog in the public void onPause() or protected void onSaveInstanceState(Bundle outState) method.

Because once the activity is recreated on orientation change, it throws an exception when you want to dismiss a dialog that is not attached to a parent.

Medo
  • 671
  • 4
  • 11
0

Ok so we solved the problem. The tablet we are testing on is running 3.2. In 3.2 the android:configChanges attribute needs to also include screen size

android:configChanges="orientation|screenSize"

within the manifest application tag.

This was helpful: How do I disable orientation change on Android?

Community
  • 1
  • 1
cren90
  • 1,367
  • 2
  • 17
  • 30