Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TechNov/a71a16afeadced3735b2f412fbe2da1f to your computer and use it in GitHub Desktop.
Save TechNov/a71a16afeadced3735b2f412fbe2da1f to your computer and use it in GitHub Desktop.
Global Exception Handling on android
Stackoverflow Link: https://stackoverflow.com/a/19968400
Handle uncaughtException, start activity:
public class MyApplication extends Application
{
public void onCreate ()
{
// Setup handler for uncaught exceptions.
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException (Thread thread, Throwable e)
{
handleUncaughtException (thread, e);
}
});
}
public void handleUncaughtException (Thread thread, Throwable e)
{
e.printStackTrace(); // not all Android versions will print the stack trace automatically
Intent intent = new Intent ();
intent.setAction ("com.mydomain.SEND_LOG"); // see step 5.
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
startActivity (intent);
System.exit(1); // kill off the crashed app
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment