0

I've implemented an ExceptionHandler to prevent the app to start the activity that crashes and it works. My Problem is that it does not display the error dialog anymore. Here the code of the ExceptionHandler:

public class MyExceptionHandler implements
    java.lang.Thread.UncaughtExceptionHandler {
private final Context myContext;
private final Class<?> myActivityClass;

public MyExceptionHandler(Context context, Class<?> c) {

    myContext = context;
    myActivityClass = c;
}

public void uncaughtException(Thread thread, Throwable exception) {

    StringWriter stackTrace = new StringWriter();
    exception.printStackTrace(new PrintWriter(stackTrace));
    System.err.println(stackTrace);// You can use LogCat too
    Intent intent = new Intent(myContext, myActivityClass);
    String s = stackTrace.toString();
    //you can use this String to know what caused the exception and in which Activity
    intent.putExtra("uncaughtException",
            "Exception is: " + stackTrace.toString());
    intent.putExtra("stacktrace", s);
    myContext.startActivity(intent);
    //for restarting the Activity
    Process.killProcess(Process.myPid());
    System.exit(0);
}
}

Does anybody have an idea, how to display the normal black crash dialog, before restarting the application ?

Thanks in advance!

Patric
  • 342
  • 4
  • 19

1 Answers1

0

I've found a solution. The problem was:

 Intent intent = new Intent(myContext, myActivityClass);
String s = stackTrace.toString();
//you can use this String to know what caused the exception and in which Activity
intent.putExtra("uncaughtException",
        "Exception is: " + stackTrace.toString());
intent.putExtra("stacktrace", s);
myContext.startActivity(intent);

Removing the startActivity, resolved the problem of the dialog, and still restarted the application as expected.

EDIT:

The dialog prompt but only because a second crashed occured because of missing data, so this answer is not correct...

Patric
  • 342
  • 4
  • 19