Android切換手機語言後讓Activity重啓問題---android:configChanges="locale|layoutDirection"

原因:沒有在AndroidManifest.xml 中申明android:configChanges

android:configChanges

Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.

解決在AndroidManifest.xml中申明 android:configChanges=”locale”

但是還是不行:
因爲4.2增加了一個layoutDirection屬性,當改變語言設置後,該屬性也會成newConfig中的一個mask位。所以ActivityManagerService(實際在ActivityStack)在決定是否重啓Activity的時候總是判斷爲重啓
需要在android:configChanges 中同時添加locale和layoutDirection。

總結:

android:configChanges=”locale|layoutDirection”

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