【问题标题】:App is killed when I change orientation of lock screen before unlocking当我在解锁前更改锁定屏幕的方向时,应用程序被终止
【发布时间】:2013-12-03 17:13:55
【问题描述】:

我在横向模式下运行游戏。当我按下锁定按钮然后再次解锁时,一切正常。我也处理这样的屏幕方向变化:

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

这一切正常,但有一个例外:

  1. 我以纵向模式运行游戏

  2. 按下锁定按钮

  3. 按下解锁按钮(这样我可以看到锁定屏幕)

  4. 将方向更改为横向并等待锁定屏幕转动

  5. 滑动锁屏返回游戏

  6. => 应用已关闭(无错误)

    有人知道如何处理吗?在滑动解锁屏幕之前锁定屏幕方向发生变化时如何防止或处理屏幕方向

【问题讨论】:

  • 应用已关闭意味着,您检查日志猫中的任何异常或错误吗?

标签: android locking screen orientation


【解决方案1】:

我相信您需要“screenSize”。即使您处理“方向”更改,屏幕尺寸也会从 X 到 Y 更改为 Y 到 X,这也算作屏幕尺寸更改。

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

【讨论】:

    【解决方案2】:
    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 或更低级别为目标,那么您的 Activity 始终会自行处理此配置更改(此配置更改不会重新启动您的 Activity,即使在 Android 3.2 或更高版本的设备上运行时也是如此)。

    来源:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多