2012-06-10 17 views
0

我在應用程序中捕獲方向更改時遇到問題。我想阻止我的應用程序窗體在設備重新定向時重新啓動。onConfigChanged()在設備方向更改時不調用

在我的應用程序中共有3個活動(第三個是FragmentActivity)。主要的用戶交互是通過FragmentActivity。

我修改清單,讓所有的活動具有以下屬性:

android:configChanges="orientation"

我也覆蓋了方法中的所有活動,並查看是否真正獲取調用它,我已經包括Log.i()聲明,但沒有任何報道。

我目前正在使用模擬器進行測試,並在執行CTRL + F12時報告方向更改。

I/ActivityManager(67):配置改變:{標度= 1.0 IMSI =二百六十零分之三百一十 LOC = EN_US觸摸= 3個鍵= 2/1/2 NAV = 3/1廣州澳凌= 1個佈局= 34 uiMode = 17 seq = 10}

有什麼我是mising?

回答

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).

+1

我只注意到它正常工作實際設備即沒有重新啓動,因爲我預期。也許是一個模擬器的問題? – Kerry

+0

這意味着如果我的應用程序目標API水平是16,我應該使用android:configChanges =「orientation | screenSize」? –

+0

我有min sdk版本10和目標sdk版本15. Android不允許我將screenSize作爲配置更改大小寫,並且它不會將屏幕方向更改委託給活動。將目標sdk版本更改爲10會帶來預期的功能。任何關於我如何能夠保持目標版本15的想法,但仍然能夠捕獲屏幕方向更改?謝謝。 –

相關問題