Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is the foreground in Android?

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?

like image 985
committedandroider Avatar asked Sep 02 '14 03:09

committedandroider


3 Answers

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

like image 58
LoPoBo Avatar answered Oct 12 '22 12:10

LoPoBo


Would foreground just be stuff that you can see and interact with on the screen.

IMHO yes, basically foreground is a state in which user can interact with the application through android component like Activity or service. Take example of Musicplayer playing music in foreground service. Also if you have to interact with application through Actvity, the activity has to be in forground. User can't interact with app even if the activity is visible but not in foreground.

like image 28
Ritesh Gune Avatar answered Oct 12 '22 13:10

Ritesh Gune


A started Service or Activity which user can see and interact is said to be in a foreground state, and the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory.The flappy bird activity is foreground because you can see it and interact with it.

To Read about it more

like image 1
vrnithinkumar Avatar answered Oct 12 '22 12:10

vrnithinkumar