Battery Saver Kills My Music Service

I am creating an Android music streaming application.

In this application, I have a Service that is responsible for playing sound from an HTTP server. Before the game, I definitely startForeground() and get a partial WakeLock so that my service is not killed. I also get WifiLock , just in case.

The service works fine ... until my phone is switched to battery saving mode. At that moment, when I turn on the battery and turn off the phone from the power source, my service is killed by fire!

Unfortunately, it doesn't even seem like onDestroy() is being called, so my notification from startForeground() remains visible, even if the service is dead.

The phone is Samsung Galaxy S6, with Android 6.0.1 on it.

Two questions:

  • Is there a way to keep the service running even though the battery stores things?
  • If not, I would like to know at least when my service is killed so that I can clear it up a bit (delete the notification and internal things).

Any suggestions?

+6
source share
1 answer

This is possible by using the front-end service in a separate process containing a partial wakelock.

 android:process="process_name" 

(documentation: http://developer.android.com/guide/topics/manifest/service-element.html )

Please note that you should not use SharedPreferences in a multiprocessor environment.

See also this problem: https://code.google.com/p/android/issues/detail?id=193802

0
source

All Articles