我正在开发一个只能在纵向模式下运行的 android 应用程序,因为布局不适合手机的横向屏幕。但是,在平板电脑和上网本上,我希望该应用程序仅在横向模式下运行。
我现在尝试检查应用程序是否在平板设备上运行,并通过 setRequestedOrientation 设置相应的请求方向。
问题是当设备尚未保持在我请求的方向时,应用程序现在崩溃,因为我在调用 setRequestedOrientation 后不久显示了一个progressDialog,这似乎泄漏了一个窗口。
Logcat 说:
10-18 21:15:30.698: E/WindowManager(653): Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41991418 that was originally added here
10-18 21:15:30.698: E/WindowManager(653): android.view.WindowLeaked: Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41991418 that was originally added here
10-18 21:15:30.698: E/WindowManager(653): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
10-18 21:15:30.698: E/WindowManager(653): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-18 21:15:30.698: E/WindowManager(653): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-18 21:15:30.698: E/WindowManager(653): at android.view.Window$LocalWindowManager.addView(Window.java:537)
10-18 21:15:31.888: E/WindowManager(653): Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41588040 that was originally added here
10-18 21:15:31.888: E/WindowManager(653): android.view.WindowLeaked: Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@41588040 that was originally added here
10-18 21:15:31.888: E/WindowManager(653): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:279)
10-18 21:15:31.888: E/WindowManager(653): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-18 21:15:31.888: E/WindowManager(653): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-18 21:15:31.888: E/WindowManager(653): at android.view.Window$LocalWindowManager.addView(Window.java:537)
10-18 21:15:34.168: E/AndroidRuntime(653): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:599)
10-18 21:15:34.168: E/AndroidRuntime(653): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:336)
10-18 21:15:34.168: E/AndroidRuntime(653): at android.view.WindowManagerImpl$CompatModeWrapper.removeView(WindowManagerImpl.java:151)
我能做些什么来防止这种崩溃?任何帮助将不胜感激。
编辑:由于我无法解决这个问题,我终于设法编辑我的布局,以便它现在允许在纵向和横向模式下使用。