标签:
1.android:configChanges="orientation|keyboardHidden"的使用
当在activity加上android:configChanges="keyboardHidden|orientation"属性,就不会重启activity.而只是调用onConfigurationChanged(Configuration newConfig).这样就可以在这个方法里调整显示方式.
在xml文件里面可以进行配置configChanges也可以在代码中动态配置
注意: 1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次
2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次
3、设置Activity的android:configChanges="orientation|keyboardHidden"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法
InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
mInputMethodManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
InputMethodManager inputManager =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(p, 0);
onConfigurationChanged为何不被调用?
英文原文如下:
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).
(From http://developer.android.com/guide/topics/resources/runtime-changes.html)
TL;DR: add "|screenSize" to configChanges when targeting API level 13+
参考:
1.http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2012/1106/516.html
2.http://www.cnblogs.com/xiaokang088/p/3540189.html
3.http://blog.csdn.net/songshimvp1/article/details/50109879
4.http://www.cnblogs.com/androidez/archive/2013/04/09/3011399.html(关闭输入法参考地址)
Android onConfigurationChanged(Configuration cfg) 无法触发问题
标签:
原文地址:http://www.cnblogs.com/charlie098765/p/5646520.html