"Battery saver" feature killing my music service
<p>I'm building a music streaming app for Android.</p>

<p>In this app, I have a <code>Service</code> which is responsible for playing audio from an HTTP server. Before playing, I make sure to <code>startForeground()</code> and acquire a partial <code>WakeLock</code>, so that my service isn't killed. I also get a <code>WifiLock</code>, just in case.</p>

<p>The service works fine... as long as my phone isn't on "battery saving mode". The minute I turn on battery saving and disconnect my phone from power source, my service is killed with fire!</p>

<p>Unfortunately it doesn't even seem that <code>onDestroy()</code> is called, so my notification from <code>startForeground()</code> stays visible, even if the service is dead.</p>

<p>The phone is a Samsung Galaxy S6, with Android 6.0.1 on it.</p>

<p>Two questions:</p>

<ol>
<li>Is there a way I can keep the service alive despite the battery saver thingy?</li>
<li>If not, I'd like to know at least when my service is killed, so that I can do a bit of cleanup (remove notification &amp; internal stuff).</li>
</ol>

<p>Any suggestions?</p>