Search code examples
androiderror-handlingcrashforceclose

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?


Solution

  • 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);
        }
    }