Our Android application uses several threads.
- The usual UI thread
- A communication layer ( a sticky service ) running several threads to connect to a socket.
- And few more, to load images, videos...
We currently have just one UncaughtExceptionHandler
defined in our Application
:
public class OurApplication extends MultiDexApplication {
public void onCreate (){
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable e) {
//...
}
});
}
}
Making some research about this concern we found this ( In this post. ), and we start thinking about every thread :
Basically, you have to implement your own instance of an UncaughtExceptionHandler, then you will have to make sure that for every thread your App runs you call setUncaughtExceptionHandler.
Since we still have some exceptions, basically coming from the sticky service, that are not handled by the UncaughtExceptionHandler
we are thinking that the handler is not properly set for some threads.
Because the default handler is a static variable of java.lang.Thread
this not seems to be possible and having just one handler within the Application
seems to be enough.
Can this be caused for example if the service starts before having defined the handler into the Application?
EDIT:
Our service doesn't run on a separate process :
<service
android:name=".servicios.ServiceBoot"
android:action="com.aplicaty.soapbox.MyService"
android:enabled="true"
android:exported="true" >
</service>
Any hints or ideas is welcome.