2

I found this answer, It helped me a lot in understanding the scenario. But, what if i have 100 Activities in my application, and crash can happen in any of them, Is there a possibility that I log all crashes from 1 single place, instead of writing this code in every single activity.

I want to save the stacktrace in some file, whenever a crash happen in application, and i want to do this globally, not by going into each activity.

 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 // Sets the default uncaught exception handler. This handler is invoked
 // in case any Thread dies due to an unhandled exception.
 Thread.setDefaultUncaughtExceptionHandler(new CustomizedExceptionHandler(
 "/mnt/sdcard/"))

;

Community
  • 1
  • 1
dev90
  • 7,187
  • 15
  • 80
  • 153

1 Answers1

1

You can do that in your Application class.

    public class MyDemoApplication extends Application {

        @Override
        public void onCreate() {
            super.onCreate();
            if (!BuildConfig.DEBUG) {
                Thread.setDefaultUncaughtExceptionHandler( <YOUR_CUSTOM_EXCEPTION_HANDLER> );
            }

        }
    }
Shantanu
  • 1,190
  • 1
  • 13
  • 23