What exactly is the foreground in Android?

committedandroider picture committedandroider · Sep 2, 2014 · Viewed 19.9k times · Source

I came across questions addressed android concepts around foreground - https://stackoverflow.com/questions/20647168/android-how-to-find-if-any-app-is-running-in-foreground. I need some clarification on the term foreground used in android. I think I have a working definition of background in android - something that happens you cannot see on the screen. Would foreground just be stuff that you can see and interact with on the screen. Like if I were to play a game of flappy bird, would the game itself(bird jumping over pipes) be the foreground because I can see it and interact it with. Based off that would the game music be in the background because I cannot see it?

Answer

LoPoBo picture LoPoBo · May 30, 2017

To put it simple, if it's interactable it's in the foreground (although the reverse may not always be true).

To be exact:

The system distinguishes between foreground and background apps. An app is considered to be in the foreground if any of the following is true:

  • It has a visible activity, whether the activity is started or paused.
  • It has a foreground service.
  • Another foreground app is connected to the app, either by binding to one of its services or by making use of one of its content providers.

If none of those conditions is true, the app is considered to be in the background. 1