How to always run some piece of code in android regardless of which activity or service run first in android?
<p>I would like to run a piece of code every time any activity or service is started.  In this piece of code, I might do things such as set the default uncaught exception handler and manage log levels.</p>

<p>The problem is that I have an activity which starts with the user clicking the application icon.  I have another which starts if a certain intent is broadcasted, possibly from another app and possibly called before the user click the launch icon.  Same goes for services.</p>

<p>I need to guarantee that a certain piece of code will be run while keeping the code clean; that is to say, without having to manually add that snippet of code to every activity and service class that I have.</p>
