1

I'm a bit confused about the background limitations of apps, and I could use an explanation. So, starting from Android 8 we have limitations on services and sending broadcasts. As for now, we can only make the service run in the background if it has the foreground notification, otherwise, it will be killed. The app is considered to be in the background if none of its activities are visible, and my questions are: 1. For how long can the app process itself live without foreground service? For instance, if I go to the home screen, thereby putting the app in the background my app can still play sounds for hours, but I expected it will be killed by the system in a couple of minutes. 2. Is foreground service somehow related to the application lifecycle? For instance, maybe if I start the foreground service then my app won't get killed or less likely to be killed by the system.

I'm asking all this because my app is using C++ libs to make VOIP calls and do other stuff in the background and I'm wondering what would happen if I just open the home screen and leave my app working, so far I've never seen the system kill the app while the call is active.

Danil.B
  • 880
  • 1
  • 11
  • 23

1 Answers1

1
  1. For how long can the app-process itself live without foreground service?

Android low memory killer daemon monitors the system constantly. If there is high memory pressure, least essential process gets killed. If there is not a memory problem, your app might live in the background for a long time. However vendors might limit the number of background processes. If this limit is 3 and your app falls to 4th place, it gets killed even if there is no memory pressure. And some vendors just kill the unvisible apps and there is nothing you can do about it. You can check this answer for a similar problem on OnePlus devices.

  1. Is foreground service somehow related to application lifecycle? For instance,maybe if I start the foreground service then my app won't get killed or less likely to be killed by the system.

According to Android Processes and Application Lifecycle documentation foreground services have the 2nd highest priority in the system. So the answer is yes, if you are running a foreground service, your app is less likely to be killed even if you do not have a visible Activity.

b4da
  • 3,010
  • 4
  • 27
  • 34