Is there is a way to be informed when one of our applications crashes on a user device ?
As a Java Swing developper, I found very, very helpful to define a custom event queue to trap every uncaught exceptions that happens in my application. To be precise, once the exception is trapped, the application sends an email to the support team with the exception trace (The killing information to make the application more and more reliable). Here is the code I use:
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.push(new EventQueue() {
@Override
protected void dispatchEvent(AWTEvent event) {
try {
super.dispatchEvent(event);
} catch (Throwable t) {
processException(t); // Basically, that method send the email ...
}
}
I looked for a way to do the same in Android apps ... but found nothing really efficient. Here is my last try:
import java.lang.Thread.UncaughtExceptionHandler;
import android.util.Log;
public class ErrorCatcher implements UncaughtExceptionHandler {
private static UncaughtExceptionHandler handler;
public static void install() {
final UncaughtExceptionHandler handler = Thread.currentThread().getUncaughtExceptionHandler();
if (handler instanceof ErrorCatcher) return;
Thread.currentThread().setUncaughtExceptionHandler(new ErrorCatcher());
}
public void uncaughtException(Thread thread, Throwable t) {
processException(t);
handler.uncaughtException(thread, ex);
}
}
This is not efficient because the application doesn't exit anymore and stay in a "zombie" state very confusing for the user.
Do you have a solution ?