How to handle global state with clean up in android
<p>I am working on an android app which has some global state (including several <code>SoundPool</code>s, which take a while to load) and I'm looking to find the best way of managing this. So far I can see two options, neither of which are perfect:</p>

<ol>
<li><p>Store the state in my main <code>Activity</code> - this hooks into the <code>Activity</code> lifecycle nicely (with opportunity to cleanup), and over screen rotations I can use <code>onRetainNonConfigurationInstance</code> and <code>getLastNonConfigurationInstance</code> to retain the state, however when navigating between activities this state will be completely lost and have to be re-loaded, which will be unacceptably slow</p></li>
<li><p>Store the state in a global singleton or an <code>Application</code> subclass - this allows the state to persist over navigation between activities, but because Application doesn't have an <code>onDestroy</code> event there is no opportunity to release the <code>SoundPool</code>s</p></li>
</ol>

<p>Any suggestions on a better way to do this? Or should I not worry about releasing the SoundPools when the app is stopped/killed?</p>

<p>Thanks, Chris</p>
