Android-Crashlytics,崩溃时运行代码 [英] Android - Crashlytics, run code during crash

查看:73
本文介绍了Android-Crashlytics,崩溃时运行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个严重的崩溃案例,这是由于某些异步在SQLite中以不正确的顺序执行操作而导致的事情崩溃了。我花了一些时间来调试所有这些,访问内部数据库将极大地帮助您。我知道如何在开发设备上访问该内部数据库,但是如果出现问题,无论设备如何,我都希望能够获得该数据库的实例。对于错误报告,我正在使用Crashlytics。

I had a bad crash case that was caused due to some Asyncs doing stuff in improper order in a SQLite and thing blew up. It took me some time to debug all that and access to the internal db would have helped immensely. I know how to access that internal db on a dev device but in case something goes wrong I would like to be able to get an instance of that db no matter the device. For error reporting I am using Crashlytics.

问题是:有没有办法让Crashlytics在崩溃收集/报告过程中运行一段代码(方法等)? ? (例如,获取数据库副本并通过电子邮件发送,或其他内容)

The question is: Is there a way to have Crashlytics run a piece of code (method, etc) during the crash collection/reporting? (For example, get db copy and email it, or something)

在文档中找不到某些内容。

Couldn't find something in the documentation.

推荐答案

可以在Crashlytics记录崩溃之前获得控制权。本质上,您必须创建自己的未捕获的异常处理程序,然后从那里调用Crashlytics的处理程序。在您的Application类中是这样的:

It is possible to get control prior to Crashlytics logging a crash. You essentially have to create your own uncaught exception handler and call Crashlytics' handler from there. Something like this in your Application class:

private UncaughtExceptionHandler originalUncaughtHandler;

@Override
public void onCreate() {
    // initialize Fabric with Crashlytics

    originalUncaughtHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(this);

    // do the rest of your oncreate stuff
}

@Override
public void uncaughtException(Thread thread, Throwable ex) {
    // do your work to add data to Crashlytics log

    originalUncaughtHandler.uncaughtException(thread, ex);
}

这篇关于Android-Crashlytics,崩溃时运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆