首页 文章

在解锁之前更改锁定屏幕的方向时,应用程序被杀死

提问于
浏览
3

我有游戏在横向模式下运行 . 当我按下锁定按钮然后再次解锁时一切正常 . 我还处理屏幕方向更改,如下所示:

<activity
    android:configChanges="orientation|keyboard|keyboardHidden"
    android:screenOrientation="portrait"

一切正常,只有一个例外:

  • 我以纵向模式运行游戏

  • 按下锁定按钮

  • 按下unloc按钮(所以我看到锁定屏幕)

  • 将方向更改为横向并在锁定屏幕转动时等待

  • 滑动锁定屏幕返回游戏

  • => app已关闭(无错误)

有谁知道如何处理这个?在刷卡解锁屏幕之前锁定屏幕方向改变时如何防止或处理屏幕方向<

2 回答

  • 1

    我相信你需要'screenSize' . 即使您处理“方向”更改,屏幕大小也会从X到Y由Y更改为Y,并且会计为屏幕大小更改 .

    <activity
        android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
        android:screenOrientation="portrait"
    
  • 1
    Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device     
    switches between portrait and landscape orientation. Thus, if you want to prevent runtime    
    restarts due to orientation change when developing for API level 13 or higher (as declared 
    by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" 
    value in addition to the "orientation" value. That is, you must declare  
    
    
    `android:configChanges="orientation|screenSize".`
    

    但是,如果您的应用程序的目标是API级别12或更低,那么您的活动始终会自行处理此配置更改(即使在Android 3.2或更高版本的设备上运行,此配置更改也不会重新启动您的活动) .

    资源:

    http://developer.android.com/guide/topics/resources/runtime-changes.html

相关问题