android 语言或屏幕方向改变后的配置

来源:互联网 发布:苹果数据恢复 编辑:程序博客网 时间:2024/05/16 01:25



4.2中,app配置了configChanges locale属性后,当app处于后台,并没有finish时,如果改变语言,并不会在resume时调用Activity重写的onConfigurationChanged函数。

原因是,4.2增加了一个layoutDirection属性,当改变语言设置后,该属性也会成newConfig中的一个mask位。所以ActivityManagerService(实际在ActivityStack)在决定是否重启Activity的时候总是判断为重启。
当在android:configChanges 中同时添加locale和layoutDirection时,才会发生app期望的事情。
SDK文档中有:
"orientation"The screen orientation has changed — the user has rotated the device.

Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.

但是在locale中却没有说明。locale中应该也有和这个类似的说明。


AndroidManifest 配置:   android:configChanges="orientation|screenSize|locale|layoutDirection"
Activity中加方法:


@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

 Log.i(TAG,"onConfigurationChanged");
}


转自:http://blog.sina.com.cn/s/blog_629712650101a1o3.html
http://www.2cto.com/kf/201201/117196.html
http://www.stormzhang.com/android/2014/07/07/learn-android-from-rookie/

0 0
原创粉丝点击