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

标题翻译的很差,你们有以为更合适的欢迎下面评论android

先看几张张图:
图片描述git

图片描述

如何使用

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必须先初始化,或原始报告工具将中止工做。github

测试

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

throw new RuntimeException("Boom!");

自定义选项

在CustomActivityOnCrash.install(this)以后调用工具

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

CustomActivityOnCrash.setLaunchErrorActivityWhenInBackground(boolean);

设置展现详细错误信息,默认为truethis

CustomActivityOnCrash.setShowErrorDetails(boolean);

启用APP Restart,默认为truespa

CustomActivityOnCrash.setEnableAppRestart(boolean);

设置从新启动的activity翻译

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

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

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

相关文章
相关标签/搜索