0

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?

Tom
  • 6,947
  • 7
  • 46
  • 76
  • I'm wondering why your windows aren't removed automatically after your app crashes. Are you using multiple processes? – cygery Aug 12 '14 at 16:56
  • No, a single process and although I've got multiple services, only one service is dealing with WindowManager. I find their persistence strange, and that they also often interfere with InputManager (you can't touch any part of the screen or software buttons). – Tom Aug 12 '14 at 16:57

0 Answers0