Android UncaughtExceptionHandler to finish app
<p>I want to close the app after logging an unhandled exception. After searching here i made the following:</p>

<pre><code>public class MyApplication extends Application {
    //uncaught exceptions
    private Thread.UncaughtExceptionHandler defaultUEH;

    // handler listener
    private Thread.UncaughtExceptionHandler _unCaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(Thread thread, Throwable ex) {
            ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
            //logging code
            //..........

            //call the default exception handler
            defaultUEH.uncaughtException(thread, ex);

        }
    };

    public MyApplication() {
        defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
        Thread.setDefaultUncaughtExceptionHandler(_unCaughtExceptionHandler);
    }
}
</code></pre>

<p>After calling <code>defaultUEH.uncaughtException(thread, ex);</code> i tried to call <code>System.exit()</code> and also  <code>android.os.Process.killProcess(android.os.Process.myPid());</code> (even i found some posts where is told to use both). The problem is that im getting a black screen and i have to force the app exit with the phone task manager. What am i doing wrong?</p>

<p>Regards</p>