android:configChanges="keyboardHidden|orientation"

一般在AndroidManifest.xml文件中都沒有使用到android:configChanges="keyboardHidden|orientation"配置,當然還是很有用的。

就是如果配置了這個屬性,當我們橫豎屏切換的時候會直接調用onCreate方法中的onConfigurationChanged方法,而不會重新執行onCreate方法,那當然如果不配置這個屬性的話就會重新調用onCreate方法了

android:configChanges=["mcc", "mnc", "locale",

"touchscreen", "keyboard", "keyboardHidden",

"navigation", "screenLayout", "fontScale", "uiMode",

"orientation", "screenSize", "smallestScreenSize"]

mcc:The IMSI mobile country code (MCC) has changed — a SIM has been detected and updated the MCC.

IMSI(國際移動用戶識別碼)發生改變,檢測到SIM卡,或者更新MCC

mnc:The IMSI mobile network code (MNC) has changed — a SIM has been detected and updated the MNC.

IMSI網絡發生改變,檢測到SIM卡,或者更新MCC

其中mcc和mnc理論上不可能發生變化

locale:The locale has changed — the user has selected a new language that text should be displayed in.

語言發生改變,用戶選擇了一個新的語言,文字應該重新顯示

touchscreen:The touchscreen has changed. (This should never normally happen.)

觸摸屏發生改變,這通常是不應該發生的

keyboard:The keyboard type has changed — for example, the user has plugged in an external keyboard.

鍵盤類型發生改變,例如,用戶使用了外部鍵盤

keyboardHidden:The keyboard accessibility has changed — for example, the user has revealed the hardware keyboard.

鍵盤發生改變,例如,用戶使用了硬件鍵盤

navigation:The navigation type (trackball/dpad) has changed. (This should never normally happen.)

導航發生改變,(這通常不應該發生) 舉例:連接藍牙鍵盤,連接後確實導致了navigation的類型發生變化。因爲連接藍牙鍵盤後,我可以使用方向鍵來navigate了

screenLayout:The screen layout has changed — this might be caused by a different display being activated.

屏幕的佈局發生改變,這可能導致激活不同的顯示

fontScale:The font scaling factor has changed — the user has selected a new global font size.

全局字體大小縮放發生改變

orientation:The screen orientation has changed — that is, the user has rotated the device.設備旋轉,橫向顯示和豎向顯示模式切換。

screenSize: 屏幕大小改變了

smallestScreenSize: 屏幕的物理大小改變了,如:連接到一個外部的屏幕上

4.2增加了一個layoutDirection屬性,當改變語言設置後,該屬性也會成newConfig中的一個mask位。所以ActivityManagerService(實際在ActivityStack)在決定是否重啓Activity的時候總是判斷爲重啓。

需要在android:configChanges 中同時添加locale和layoutDirection。

在不退出應用的情況下切換到Settings裏切換語言,發現該Activity還是重啓了。



作者:qiujiwuhen
鏈接:https://www.jianshu.com/p/15d36c2f296b
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯繫作者獲得授權並註明出處。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章