onConfigChanged()在设备方向更改时不调用

时间:2012-06-10 08:41:28

标签: android android-orientation android-configchanges

我在捕捉应用中的方向更改时遇到问题。我希望在设备重新定位时阻止我的应用表单重新启动。

我的应用程序中共有3个活动(第三个是FragmentActivity)。主要的用户交互是通过FragmentActivity。

我更改了清单,以便所有活动都具有以下属性:

android:configChanges="orientation"

我还在所有活动中覆盖了onConfigurationChanged()方法,看看它是否实际被调用我已经包含了Log.i()语句,但是没有任何报告。

我正在使用模拟器对此进行测试,当我执行CTRL + F12时会报告方向更改。

  

I / ActivityManager(67):配置已更改:{scale = 1.0 imsi = 310/260   loc = en_US touch = 3 keys = 2/1 / 2 nav = 3/1 orien = 1 layout = 34 uiMode = 17   SEQ = 10}

我有什么东西在迷惑吗?

1 个答案:

答案 0 :(得分:6)

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

Caution: 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 decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).