Android抓住应用崩溃

时间:2012-08-01 10:53:02

标签: android exception-handling

我想知道是否有可能覆盖一个方法(或类似的东西),当应用程序因某些异常而崩溃时将调用该方法。

我想这样做,所以下次用户登录时,会向他/她发出一条消息,告知应用已崩溃,并且该错误将尽快修复。

3 个答案:

答案 0 :(得分:6)

使用ThreadsetDefaultUncaughtExceptionHandler()

答案 1 :(得分:1)

我找到了一个完美的小解决方案:

创建我的应用程序时,我会执行以下操作:

// Ceck if the app crashed last time


    if(this.getIO().readPrimitiveInternalMemoryBoolean(FileNames.SpaceDroid.CrashReport) == true) {
                this.getGameLog().d(classTAG, "App crashed last time");

            }
            else {
                this.getGameLog().d(classTAG, "App didn't crash last time");

            }

            // Flag the app as chrashed and when the app is exited, then mark it as false.
            this.getIO().writePrimitiveInternalMemory(FileNames.SpaceDroid.CrashReport, true);

当我的应用程序关闭时,我会这样做:

@Override
    public void onDispose() {
        super.onDispose();
        this.getIO().writePrimitiveInternalMemory(FileNames.SpaceDroid.CrashReport, false);

    }

答案 2 :(得分:0)

您可以在日志中使用try catch语句和日志信息。此外,谷歌播放提供了一种机制,可以通知您生产中的应用程序崩溃。