应用放到android4.0终端,遇到了异常退出的问题.
2011-12-20 15:27
190 查看
【重现方法】
1. 在有些activity中横屏时,应用会异常退出。
【原因】
在这些activity的onCreate方法中使用了广播机制,
如:registerReceiver(m_oSDReceiver, getSdcardIntentFilter());
在横屏时会多次调用onCreate, 即多次注册了广播,导致死机。
【分析结果】
1. 如果你的sdk版本是2.3之前的,要做如下处理如下:
1)在AndroidManifest.xml中,找到对应的activity添加: android:configChanges="orientation|keyboardHidden|locale
2) 在activity 中重载onConfigurationChanged方法
如果配置了android:configChanges这个属性,当我们横竖屏切换的时候会直接调用onConfigurationChanged方法,而不会重新执行onCreate方法,那当然如果不配置这个属性的话就会重新调用onCreate方法.
2. 如果sdk是3.2以后的版本,需要添加 screenSize属性,如下:
1) android:configChanges="orientation|keyboardHidden|locale|screenSize"
2) 在activity 中重载onConfigurationChanged方法
添加screenSize的原因:
"screenSize" The current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. 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).
Added in API level 13.
1. 在有些activity中横屏时,应用会异常退出。
【原因】
在这些activity的onCreate方法中使用了广播机制,
如:registerReceiver(m_oSDReceiver, getSdcardIntentFilter());
在横屏时会多次调用onCreate, 即多次注册了广播,导致死机。
【分析结果】
1. 如果你的sdk版本是2.3之前的,要做如下处理如下:
1)在AndroidManifest.xml中,找到对应的activity添加: android:configChanges="orientation|keyboardHidden|locale
2) 在activity 中重载onConfigurationChanged方法
如果配置了android:configChanges这个属性,当我们横竖屏切换的时候会直接调用onConfigurationChanged方法,而不会重新执行onCreate方法,那当然如果不配置这个属性的话就会重新调用onCreate方法.
@Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){ //横向 }else{ //竖向 } }
2. 如果sdk是3.2以后的版本,需要添加 screenSize属性,如下:
1) android:configChanges="orientation|keyboardHidden|locale|screenSize"
2) 在activity 中重载onConfigurationChanged方法
添加screenSize的原因:
"screenSize" The current available screen size has changed. This represents a change in the currently available size, relative to the current aspect ratio, so will change when the user switches between landscape and portrait. 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).
Added in API level 13.
相关文章推荐
- 应用放到android4.0终端,遇到了异常退出的问题.
- Terminal(终端)中代理的配置---Linux应用中遇到的问题笔记
- ActiveMQ-cpp客户端程序应用异常退出问题
- MSSQL2000的官方JDBC在应用动态代理机制遇到的异常问题解决
- Android 应用按返回键异常退出的问题
- qt工程迁移过程中遇到的问题(opencv工程异常退出)
- 关于cocos2dx嵌入到iOS应用中遇到触摸机制异常的问题
- MSSQL2000的官方JDBC在应用动态代理机制遇到的异常问题解决
- 关于开发Android应用时写从图库选择头像功能时遇到的一些问题。
- web 应用在瞬间高并发时候会遇到的问题
- Tomcat应用中遇到的几个问题
- 退出重进程序,TextView不可见(不显示)问题(极少情况下遇到)
- C# 调用 C++ 写的Dll 遇到的问题(调用DLL 自动退出)
- ssh终端自动logout或自动退出,以及不能用root直接登录的问题
- CFileDialog程序异常退出问题
- android应用sqlite遇到的问题
- c# 退出应用时进程不关闭问题
- jenkins自动化构建iOS应用配置过程中遇到的问题
- 百度地图应用开发遇到的问题