I have set an UncaughtExceptionHandler
, so that I can write out stack traces to disk when my app crashes. I set this handler like this:
if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
exceptionHandler = new CustomExceptionHandler(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString(),
null, this);
Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
}
where CustomExceptionHandler
implements UncaughtExceptionHandler
. I keep the instance in my Activity
, so I can use it for some other functionality (deleting the stack traces, retrieving them, etc).
I call the above piece of code in the onCreate
of my Activity
, but it seems to only trigger the first time any Activity
is run.
I see the Thread.setDefaultUncaughtExceptionHandler
call is static though, does that mean I can only set that handler only once in my app? Or can I set it per thread?
From docs
Yep, this handler is global and you need to set it once per app