自定义应用Crash时系统显示的对话框

465 查看

标题翻译的不好,大家有觉得更合适的欢迎下面评论

先看几张张图:

如何使用

1,添加依赖

dependencies {
    compile 'cat.ereza:customactivityoncrash:1.3.0'
}

2,在Manifest中配置

<activity
   android:name="cat.ereza.customactivityoncrash.activity.DefaultErrorActivity"
   android:label="@string/customactivityoncrash_error_activity_error_details_title"
   android:process=":error_activity" >
        <intent-filter>
            <action android:name="cat.ereza.customactivityoncrash.ERROR" />
        </intent-filter>
</activity>

3,在Application中设置

@Override
    public void onCreate() {
        super.onCreate();

        //Install CustomActivityOnCrash
        CustomActivityOnCrash.install(this);

        //Now initialize your error handlers as normal
        //i.e., ACRA.init(this);
        //or Crashlytics.start(this);
    }

注意:如果你已经有ACRA,Crashlytics或任何类似的库在您的应用程序,它仍然会正常工作,但CustomActivityOnCrash必须先初始化,或原始报告工具将停止工作。

测试

在程序中添加下面一行代码,必须保证他能被执行

throw new RuntimeException("Boom!");

自定义选项

在CustomActivityOnCrash.install(this)之后调用

设置ErrorActivity在后台启动,默认为true

CustomActivityOnCrash.setLaunchErrorActivityWhenInBackground(boolean);

设置展示详细错误信息,默认为true

CustomActivityOnCrash.setShowErrorDetails(boolean);

启用APP Restart,默认为true

CustomActivityOnCrash.setEnableAppRestart(boolean);

设置重新启动的activity

CustomActivityOnCrash.setRestartActivityClass(Class<? extends Activity>);

自定义请参阅Github:https://github.com/Ereza/CustomActivityOnCrash

注:如果使用Android Studio添加compile无效的话,建议下载library以module的形式添加依赖