简体   繁体   中英

Tablet Application Crashes on Orientation Change

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.

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
}

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM