1

What is the main thread of execution of an android app and/or activity ?

All my code has begun in onCreate, however, I want/need to know if it is possible to override the part of the app/activity that calls onCreate?

I want to put a "top most" try/catch around my activity as a catch all for all possible exceptions, instead of putting a try/catch inside every single method I override.

samus
  • 6,102
  • 6
  • 31
  • 69

1 Answers1

3

In android, main entry point of an application is the Zygote service. Zygote handles the main method, starts up your application then activity cycle. For better understanding, study the Zygote service of Android. deals with Applicationmanager Service, ActivityStack Activity Threadds etc.

If you want to catch all the uncaught exceptions, you can simply use Thread.setDefaultUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler). But you need to be careful about where you throw exceptions. If you throw an exception in ui-thread and don't caught it, even if you set the uncaughtexceptionhandler, it will most likely cause your application to stop.

Onur
  • 5,617
  • 3
  • 26
  • 35
  • Thanks. setDefaultUncaughtExceptionHandler example http://stackoverflow.com/questions/13416879/show-a-dialog-in-thread-setdefaultuncaughtexceptionhandler – samus May 09 '14 at 13:54