0

I have a few questions about certain behavior on Android devices. I'm using SDK which ask the user to turn-off battery optimization for the app. I'm also running a foreground service which implements some interfaces from said SDK. I need the foreground service to run as long as possible with out any other interaction with the app.

What I wanted to know is:

  1. If the user allows to turn off the battery optimization - does it mean that the OS can't kill my foreground service (or it will be killed under some strict conditions).

  2. If the user doesn't allow to turn off the battery optimization - does it mean that the OS will kill my service more easily?

  3. If under some conditions the OS kills my service, the foreground service is also dead, will the service come back to life if I made it START_STICKY and if so, how long does it take it to restart?

Keselme
  • 3,779
  • 7
  • 36
  • 68

1 Answers1

0
  1. Each manufacturer implements Android in a different way, so a specific behaviour seen on (as example) Samsung could not be the same on Xiaomi, and vice-versa. Battery optimization could not involve Services in the way you expect, or maybe yes. It's impossibile to find a fixed rule for this.
  2. (same as 1)
  3. the restart is near-instant, it takes just the time to empty memory, release locks/files and similar things and finally run an "internal startService()" method again.

I'm using a Background Service as the main purpose in my App (it creates some floating windows/interfaces when needed) and I never seen that the OS killed my Service in more than 6 years. However the Service should support to be killed and restarted without FC something.

emandt
  • 2,547
  • 2
  • 16
  • 20
  • You are using a background service as the main purpose in your app, but this question is talking about foreground services. Two very different things when it comes to how likely they are to be terminated by the OS. – Simon Forsberg Aug 08 '22 at 14:38