On May 20, 3:41 am, Nik Bhattacharya <[email protected]> wrote: > I have an activity that starts up a LocalActivityManager, which in > turn starts up several Activities and pulls in their decor views and > puts them into current activities view. However, there is the case > that a particular activity might be a rogue activity and will cause > the entire host activity to crash. One such case is the subactivity > causes an OutOfMemory exception due to excessive Bitmap allocation. > > My thought was that I could make my host application implement > UncaughtExceptionHandler and assign the Thread's default uncaught > exception handler to it. [...]
First, note there is a difference between setUncaughtExceptionHandler () and setDefaultUncaughtExceptionHandler(). One applies to a single thread, the other to all threads in the VM. Second, the app framework already provides a global uncaught exception handler. The exception traces with the "AndroidRuntime" tag are generated here, and then the VM is killed. See frameworks/base/core/ java/com/android/internal/os/RuntimeInit.java. If you specify your own, you will override the app framework's behavior for all threads. Uncaught exceptions are first handled by the per-thread handler, then the per-thread-group handler, and then by the global handler. This doesn't strike me as a good idea. You're going to have some half- dead things sitting around, probably holding on to memory and other resources. If you're not going to shut the VM down, then whatever bit of code failed must clean up after itself and stop, presumably through the use of "finally" blocks that ensure everything gets taken care of. This seems like it would be difficult to manage from a single global handler. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

