Android - UncaughtExceptionHandler : Max time to complete its execution

149 Views Asked by At

I understand that UncaughtExceptionHandler runs on MainThread to handle all the unhandled exceptions. Am trying to write the throwable and thread info to a file, but I have to do this on main thread only. I am concerned that doing so may throw ANR on android, since IO operations are relatively time taking and expensive operations.

What is the max time limit that main thread can wait while executing uncaught exception handler ?

1

There are 1 best solutions below

1
On

The standard ANR timeout is 5 seconds. If you exceed that, the user will get the ANR dialog. You should be able to write a small file in that time, but it is no guarantee.

If you think your write may take longer, consider serializing the exception into a Bundle and sending it to an IntentService that runs in a separate process so it can do its work without blocking the main process's main thread. (This works fine, I've done it.)