Yarh
Yarh

Reputation: 4617

How to replace standard error message?

When application crashes we can see something like Your wonderful app was stopped. How can I change this text?

Upvotes: 3

Views: 1548

Answers (3)

Alan
Alan

Reputation: 608

Implements UncaughtExceptionHandler and assign it to your Application

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        Thread.setDefaultUncaughtExceptionHandler(new CrashHandler());
    }
}

public final class CrashHandler implements UncaughtExceptionHandler {
    private final UncaughtExceptionHandler handler;

    public CrashHandler() {
        // Uncomment this line if you want to show the default app crash message
        //this.handler = Thread.getDefaultUncaughtExceptionHandler();
    }

    @Override
    public void uncaughtException(final Thread thread, final Throwable throwable) {
        // Show pretty message to user

        // Uncomment this line to show the default app crash message
        //this.handler.uncaughtException(thread, throwable);
    }
}

Upvotes: 3

Boardy
Boardy

Reputation: 36217

Those errors are normally shown due to an unhandled exception. If you set an unhandled exception handler at the beginning of the program and then in there show the message you want to view.

I'm not entirely sure however, if after your message has shown whether the default android alert is also shown but this may be what you're after.

Upvotes: 3

Benil Mathew
Benil Mathew

Reputation: 1634

i think this is what you are looking for

ACRA - Application Crash Report for Android

A synopsis from the site

When a crash occurs, you can choose and configure 4 different ways of interacting with the user:

Silent (default): ACRA actions are not visible. The crash report is sent and then the default android crash system does its job (Force Close dialog)

Toast: When the crash occurs, ACRA displays a toast and simultaneously sends the report.

Notification: An optional toast is displayed on application crash, but the report is not sent immediately. A status bar notification is published warning the user that he should send a report. When selected, the notification displays a dialog asking for the authorization to send the report, with an optional user comment.

Dialog: since 4.3.0b1, experimental, allows to display a crash dialog without the need of a status bar notification.

Hope that link helps.

Upvotes: 0

Related Questions