0

For devices targeting API < 26, I have a service which remains the background until it receives a signal to do work. At that point, the service notifies the user and moves itself to the foreground, where it will complete its task and withdraw back into the background.

My problem is that sometimes, the service will not complete the task after receiving the signal. I am in the process of troubleshooting the cause, but assuming it's not a case of internal life cycle error (crash, stopSelf(), etc...), is there any possibility that the system shuts down my service permanently without restarting it?

I am not ruling out the case of internal error, but it would help me to narrow down my search. I know that the system should restart the service in case it's low on memory (which I don't think is the case here). Keep in mind that API >= 26 has a different implementation, and as a last resort would be adopted for lower versions, but I would like to avoid that.

I apologise in advance for being as vague as possible.

daedsidog
  • 1,732
  • 2
  • 17
  • 36
  • I deleted my answer b/c I think I misunderstood START_STICKY until I just read a [little more](https://stackoverflow.com/questions/9093271/start-sticky-and-start-not-sticky) on it, and I think you are right that the system should try to start it up again, but I've never seen that happen, so I will defer. – greeble31 Sep 01 '18 at 15:43
  • On what devices does this occur? There are many devices out there that. by default, do NOT restart Services if they are killed (even if the Service returns START_STICKY). These devices do this for "battery saving" reasons. On these devices the user MUST manually add the application to a list of applications that are allowed to run in the background (sometimes known as "protected apps"). – David Wasser Sep 03 '18 at 15:58
  • I don't know for certain, but a rough estimate is about 90% of devices, if not more. How can I otherwise hope to restart services that die if this kind of shut down does not call any of the service's callbacks? – daedsidog Sep 03 '18 at 18:28

0 Answers0