How do i shut down everything in any case of my app being closed?
<p>please hold back on the downvotes for a second and read.</p>

<p>After my question
<a href="http://stackoverflow.com/questions/12707767/is-there-a-way-to-create-a-controlling-instance-that-controls-several-activities">Is there a way to create a controlling instance that controls several activities of my app?</a></p>

<p>and after reading <a href="http://stackoverflow.com/questions/10387774/detect-when-application-is-closed">detect when application is closed</a></p>

<p>i am wondering... i have lots of activities in my app, and several services, i access about all the hardware that the device has. Access to those things makes sense for as long as the app is running. Activities can change but the need for access to those things is there in every single one of them (slight exaggeration).</p>

<p>I know of two ways that seem suitable for my needs.</p>

<p>1) i extend Application and instantiate some objects there that access or calculate stuff that is needed everywhere</p>

<p>2) i do the same in a subclass of Activity</p>

<p>In both cases i would like to unregister broadcastreceivers and stop services. Services are not bound (for a reason). So whats the proper way to close and unregister things in all those cases that can happen ?</p>

<ul>
<li><p>its possible that onDestroy is not called</p></li>
<li><p>i am not notified of my process being closed/killed by the system</p></li>
</ul>

<p>So how do i create something that is always there for all my activities but stops and cleans up whenever my app is being closed ?!</p>
