奔溃问题

android运行的时候难免会有一些空指针(NullPointerException)或者下标越界(IndexOutOfBoundsException),用户使用的过程操作某一个按钮的时候,就发生了崩溃.导致app直接闪退,降低用户体验,因此导致用户流失

 

1.在项目根目录的build.gradle文件中添加

allprojects {    repositories {        maven { url 'https://dl.bintray.com/xuuhaoo/maven/'}    }}

2. 在项目的build.gradle文件中添加依赖包

implementation 'com.tonystark.android:defense_crash:2.0.0'

3.在项目的Application中初始化操作

   DefenseCrash.initialize();           DefenseCrash.install(this);

 4.在项目的Application中实现 implements IExceptionHandler 接口

 

    public class MyApp extends Application implements IExceptionHandler {        @Override        protected void attachBaseContext(Context base) {            super.attachBaseContext(base);            // step1: Initialize the lib.            DefenseCrash.initialize();            // setp2: Install the fire wall defense.            DefenseCrash.install(this);        }        @Override        public void onCaughtException(Thread thread, Throwable throwable, boolean isSafeMode) {            // step3: Print the error when crashed during runtime.            throwable.printStackTrace();            // step4: Upload this throwable to your crash collection sdk.        }        @Override        public void onMayBeBlackScreen(Throwable throwable) {            // onLayout(),onMeasure() or onDraw() has breaks down,            // it causes the drawing to be abnormal and the choreographer to break down.            // We will notify you on this method,you’d better finish this activity or restart the application.        }        @Override        public void onEnterSafeMode() {            // We enter the safe mode to keep the main looper loop after crashed.You’d better do nothing here,we just notify you.        }    }

 

 5.大功告成,这样用户在使用app是就不会出现奔溃闪退的现象啦!!!

 

更多相关文章

  1. android开源项目学习
  2. Vue项目判断 是移动端还是PC , 微信 , iOS , 安卓
  3. GreenDAO 3.x项目开发实战持续更新ing — Android(安卓)ORM框架(
  4. Android(安卓)studio 为项目添加启动等待界面
  5. android 如何快速生成jar包
  6. 在 Android(安卓)的 IM 应用中使用 asmack 库实现用户头像的传输
  7. Ubuntu android adb 使用
  8. 解决Android(安卓)Studio 不能启动或新建项目的情况
  9. ActionBarSherlock使用教程

随机推荐

  1. 无需手工设计,从零开始搜索损失函数
  2. 第五章 主生产计划MPS 第4~5节 MPS计划生
  3. nodejs搭建本地服务器
  4. 第五章 主生产计划MPS 第1~3节 计划方案
  5. 如何在Mac上设置和使用Apple Pay
  6. 飞鸽内网穿透操作使用说明
  7. 冒烟测试怎么做?
  8. 分布式机器学习中的拜占庭问题
  9. 新手正确提问姿势
  10. CentOS 7最小化安装对系统初始化