Luke Taylor
Luke Taylor

Reputation: 9599

Android catch app crash

I was wondering if it would be possible to override a method (or something like that), that will be called when the application will crash due to some exception.

I'd like to do this, so the next time the user loggs in, it gives him/her a message that the app has crashed and that the bug will be fixed as soon as possible.

Upvotes: 1

Views: 1503

Answers (3)

Luke Taylor
Luke Taylor

Reputation: 9599

I found a simple little solution that works perfectly:

When my app is created I do something like this:

// 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);

When my app is being closed, then I do something like this:

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

    }

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006604

Use Thread and setDefaultUncaughtExceptionHandler().

Upvotes: 6

jloriente
jloriente

Reputation: 1541

You could use a try catch statement and log info in your logs. Also google play provides a mechanism to notify you about crashes in your apps in production.

Upvotes: 0

Related Questions