There are many reasons why foreground application discovery. for example, as a trigger for push notification GCM / C2DM - many applications will have a good reason for implementing different behaviors when the application is front and rear. Another reason may be that services that consume valuable resources, such as, for example, server requests in a background task, can be destroyed.
Just to be clear: definition (as I see) for a background application :
An application in which none of its actions is called by the onStart() method and does not yet call the onStop() method. that since activity is visible to the user in this life cycle only at this time.
On the other hand -
Google doesn't seem to want the app to respond to the home button (this is not part of the API)
reacts to onBackPressed() to "root / main" activity as an indicator of the Activity exit, of course, not a good idea (because many users use the home button and not the back button)
there is no method in the API to determine if an application is a priority (according to my definition ..)
if I have not missed something in the API, and it really is - Why is there no reason to easily determine if the application is in the foreground or not ???? !!!!
what I know, I can do to determine if the application is foreground in this thread - How to determine when an Android application goes to the background and comes back to the fore
but as @Emil says it requires special permission or requires some complex logic that quickly becomes problematic to maintain, and it smells like a bad approach (although what I'm doing now because I donβt have a better idea ...)
my questions are mostly :
Is there an API method for a good reason?
Is the application in the foreground or not - a bad approach?
Is there any other way to find out if an application is prioritized or not?
android activity-lifecycle application-lifecycle
Tal kanel
source share