On Sun, Jul 29, 2012 at 11:24 AM, Jim Morris <jim.mor...@lecere.com> wrote: > I am surprised to find that Android apparently does not call > onDestroy, onStop, or onPause after a fatal exception occurs (e. g. a > null pointer fatal exception). I have put the following code into two > activities that are around when a fatal exception occurs. None of this > code gets executed in either activity when a fatal exception occurs in > one of the activities. > > public void onStop() { Log.i("JIM","CALL ONSTOP"); super.onStop(); } > > public void onDestroy() { Log.i("JIM","CALL ONDESTROY"); > super.onDestroy(); } > > public void onPause() { Log.i("JIM","CALL ONPAUSE"); > super.onPause(); } > > So this begs the question: What method is called that will allow me > to, for example, close the database so the database does not get > destroyed when a fatal exception occurs?
The database will not be "destroyed" when a fatal exception occurs. You can wrap whatever code you want of yours in try/catch blocks for any RuntimeExceptions that you fear. This is standard Java. You can use setUncaughtExceptionHandler() and setDefaultUncaughtExceptionHandler() on Thread to get control on an unhandled exception. This too is standard Java. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.8 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en