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.

  • 相关阅读:
    jQueryrocket
    jQueryrocket
    jQueryrocket
    jQueryrocket
    jQueryrocket
    SharePoint 2013 Workflow Manager 1.0 卸载
    SharePoint 2013 Workflow Manager 1.0 远程服务器返回错误: (400) 错误的请求。 不支持查询字符串中的 api-version
    SharePoint 2010 使用Install-SPSolution部署wsp包状态一直是”正在部署”
    SharePoint 2010管理中心服务器提示“需要升级”
    SharePoint 2010:“&”作为SharePoint账号密码引起的错误
  • 原文地址:https://www.cnblogs.com/wanqieddy/p/2549435.html
Copyright © 2011-2022 走看看