I want to close the app after logging an unhandled exception. After searching here i made the following:
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);
}
}
After calling defaultUEH.uncaughtException(thread, ex);
i tried to call System.exit()
and also android.os.Process.killProcess(android.os.Process.myPid());
(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?
Regards