Catch all possible android exception globally and reload application
In your onCreate
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
//Catch your exception
// Without System.exit() this will not work.
System.exit(2);
}
});
Ideal way to set global uncaught exception Handler in Android
That should be all you need to do. (Make sure you cause the process to halt afterward -- things could be in an uncertain state.)
The first thing to check is whether the Android handler is still getting called. It's possible that your version is being called but failing fatally and the system_server is showing a generic dialog when it sees the process crash.
Add some log messages at the top of your handler to see if it's getting there. Print the result from getDefaultUncaughtExceptionHandler and then throw an uncaught exception to cause a crash. Keep an eye on the logcat output to see what's going on.
Global Exception Handlers in Java
- The name is a bit misleading, because using that method will set a default exception handler for all threads.
- Make sure no exceptions can be thrown from your exception handler.
- If you're doing GUI stuff from your exception handler, make sure you're doing it from the right thread.
- An uncaught exception will only stop the thread where the exception took place, if that also causes the process to terminate depends on any other threads that might be running.
Related Topics
Passing Data from One Activity to Another Using Bundle - Not Displaying in Second Activity
Bitmap Recycle with Largeheap Enabled
How to Implement a View Holder
How to Use the Firebase Server Timestamp to Generate Date Created
Updating Progress Dialog in Activity from Asynctask
Android - Out of Memory Exception When Creating Bitmap
Android Studio - Unable to Merge from Svn Branch
Org.JSON.JSON Exception:End of Input at Character 0
Marking Sms Messages as Read/Unread or Deleting Messages Not Working in Kitkat
Making the Android Emulator Run Faster
How to Make Sticky Headers in Recyclerview? (Without External Lib)
How to Use Icons and Symbols from "Font Awesome" on Native Android Application
Support Fragmentpageradapter Holds Reference to Old Fragments
Background Listview Becomes Black When Scrolling
Android Viewpager with Bottom Dots
How to Obtain Signing Certificate Fingerprint (Sha1) for Oauth 2.0 on Android