android:configChanges
来源:互联网 发布:淘宝闲鱼珠宝拍卖真假 编辑:程序博客网 时间:2024/05/22 14:51
每次Power键的时候,app是会强制回到竖屏状态的,并且会重新调用Activity的onCreate(),当然很多时候这不是我们想要的。所以就需要用到android:configChanges了,在配置文件里设置 android:configChanges="keyboardHidden|orientation",这样在屏幕方向改变的时候就不会重新调用 Activity的onCreate(),而是调用onConfigurationChanged(),然后在Activity里重载下
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
//横向
}else{
//竖向
}
}
一般就这么处理下就可以了,要命的是用到了SurfaceView,而SurfaceView和Thread的生命周期是不一样的,唉,这里要说一下Google提供的sample了,里边有bug!!
由于每次Power键的时候会调用SurfaceView的surfaceDestroyed(SurfaceHolder holder),但是回到app的时候又没有执行surfaceCreated(SurfaceHolder holder),于是就咯屁了~~
目前想到一个能解决的方案是在onConfigurationChanged(Configuration newConfig)里手动处理,surfaceDestroyed(SurfaceHolder holder)+surfaceCreated(SurfaceHolder holder)+pause()处理。。。
唉,希望可以找到一个比较好的解决方案吧。
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
//横向
}else{
//竖向
}
}
一般就这么处理下就可以了,要命的是用到了SurfaceView,而SurfaceView和Thread的生命周期是不一样的,唉,这里要说一下Google提供的sample了,里边有bug!!
由于每次Power键的时候会调用SurfaceView的surfaceDestroyed(SurfaceHolder holder),但是回到app的时候又没有执行surfaceCreated(SurfaceHolder holder),于是就咯屁了~~
目前想到一个能解决的方案是在onConfigurationChanged(Configuration newConfig)里手动处理,surfaceDestroyed(SurfaceHolder holder)+surfaceCreated(SurfaceHolder holder)+pause()处理。。。
唉,希望可以找到一个比较好的解决方案吧。
- android ConfigChanges
- android ConfigChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- android:configChanges
- 11.10学习随记
- python中的变长参数
- java环境变量配置
- jsp标准标签库知识总结
- GSM移动智能网计费检测方法
- android:configChanges
- iPad开发实现横竖屏幕调整View的尺寸
- JSP标准标签库
- 真实案例 京东商城订单处性能瓶颈,如何解决京东商城的性能瓶颈?
- WPF核心技术(奋斗的小鸟)_PDF 电子书
- GPRS计费
- 连接数据库
- IMPDP ORA-06512
- 学习JSTL