0

I'm trying to make app close when some uncaughtException happens, but android show a message to try to restart the application and the application stays in slow motion or just black screen, I made a class to extends in my activity to overriding the method uncaughtException() to catch logs to send than to sentry.io and using:

public class MyExceptionHandler implements 
  Thread.UncaughtExceptionHandler {

  public MyExceptionHandler(Activity context) {

    Thread.setDefaultUncaughtExceptionHandler(this);
  }

  @Override
  public void uncaughtException(final Thread thread, final Throwable ex) {
    Log.e("ERROR", ex.toString());

    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(0);
  }
}
Clamorious
  • 415
  • 1
  • 7
  • 14

1 Answers1

0

You can use

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

Got idea from this answer.

karandeep singh
  • 2,294
  • 1
  • 15
  • 22