I'm writing an app for Android that uses the WindowManager
class to create popup windows. Everything is working fine, except I am worried about my app crashing. I'm operating under the assumption that, no matter how well my app is coded, someone somewhere will experience a crash.
That said, I'd like to find a graceful solution to my app crashing. At present, if an uncaught exception is thrown anywhere in my app the window remains visible and because of the window type and size I am using, the system dialog "App has crashed," is not touchable. This leads to a deadlock and often the device needs to be hard reset to fix this issue.
My first thought was to set a Thread.UncaughtExceptionHandler
that had the code below:
Process.killProcess(Process.myPid());
System.exit(0);
Unfortunately, while I see the method is being called in the logs, the app isn't actually crashing as I would expect (process death, all windows disappear, etc).
Is there a more graceful way to handle crashes when using WindowManager#addView
from a background service?