zoukankan      html  css  js  c++  java
  • 应用放到android4.0终端,遇到了异常退出的问题.

    【重现方法】

    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这个属性,当我们横竖屏切换的时候会直接调用onCreate方法中的onConfigurationChanged方法,而不会重新执行onCreate方法,那当然如果不配置这个属性的话就会重新调用onCreate方法.

      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.

  • 相关阅读:
    jdbc的入门学习
    java代码生成Excel文件3000条自定义属性的的域账户名
    java面试题
    node图片资源捉取
    运用node真机调试移动web项目
    node读取文件转换json文件
    微信小程序页面导航功能
    JavaScript值全等判断
    微信小程序海报生成功能
    JavaScript常用数组操作方法,包含ES6方法
  • 原文地址:https://www.cnblogs.com/wanqieddy/p/2549435.html
Copyright © 2011-2022 走看看