0

I found a solution for a global try-catch in an activity. (here) Can I do something similar with a service?

Community
  • 1
  • 1
Andrzej Gis
  • 13,706
  • 14
  • 86
  • 130

1 Answers1

2

Thread.setDefaultUncaughtExceptionHandler() is for your entire application. You can call Thread.setDefaultUncaughtExceptionHandler() from a Service if you wish, instead of from an Activity. However, you only need to call it once for your application, in most cases.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Just to make it clear, do I have to put it in a SomeBaseActivity and make every other activity inherit from it? Or calling it once in my InitialActivity is enough? – Andrzej Gis Jul 01 '12 at 14:41
  • 1
    @gisek: Once in your `InitialActivity` is enough, for the lifetime of that process. That being said, you do need to make sure that it will be called no matter how your process is created -- if they might get to your app by means other than `InitialActivity`, you have a problem. This is why many apps, such as those using ACRA, will tend to use a custom `Application` class for this. – CommonsWare Jul 01 '12 at 15:01