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.

  • 相关阅读:
    Xcode 单元测试
    Oracle积累
    懒人小技巧, Toad 常用偷懒方法
    改变UITableView选中行高亮的颜色
    苹果企业版帐号申请记录
    RGB颜色设置错误
    IOS 设置文件是否使用ARC
    懒人的小技巧, 批处理修改IP
    Go连接MYSQL
    Go中的函数和闭包
  • 原文地址:https://www.cnblogs.com/wanqieddy/p/2549435.html
Copyright © 2011-2022 走看看