Android studio 全局捕获异常

1.安卓的异常分为运行异常和编译异常
在这里插入图片描述

2.异常捕获的原理
Thread.UncaughtExceptionHandler 是 Java 虚拟机处理由于未捕获异常而导致程序停止运行的接口当一个线程由于未捕获异常而停止运行的时候,Java 虚拟机就会通过 Thread的getUncaughtExceptionHandler() 方法拿到当前 Thread 的 Thread.UncaughtExceptionHandler,并调用该 Thread.UncaughtExceptionHandler 的
uncaughtException 方法。

  1. 捕获异常后,如何优雅退出

      android.os.Process.killProcess(android.os.Process.myPid());
      System.exit(10);
    
4.bugly的使用和场景    

注册bugly,继承bugly,写个bug看log

布局文件只写个button 按钮

 <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:onClick="click"
        />

在AndroidManifest.xml 清单文件中 注册

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name=".EHApplication">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

在MainActivity中的代码

package 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值