Detect when a particular application (not mine) becomes visible / not visible to the user
<p><strike>I am currently trying to write an app that will change certain settings automatically (turn off sound, etc) when an application becomes active and to revert back to the original settings when the application is no longer active. </strike></p>

<p><strong>EDITED</strong>
Sorry, I believe I explained the question poorly. I am currently trying to write an app that will be able to detect when a certain application (for example, youtube app) becomes visible to the user, meaning that the user has just launched/navigated to the youtube app. </p>

<p>When I detect this, I want to perform certain setting changes, such as turning off the phone's sound (I have already figured this part out). And then, when I detect that the youtube app is no longer visible to the user, I want to restore the settings back to what they were.</p>

<p>What I want to know is the mechanism to detect when any application at all (not my application) becomes visible / not visible to the user. </p>

<p>Kind of like what the app Tasker does.</p>

<p>I am trying to figure out how it accomplishes this. There does not seem to be any broadcast receivers that will notify on applications becoming active. One way that I can think of is to create a service that constantly polls the currently running tasks.. but this seems like it will give very bad performance.</p>

<p>Is there any alternative that someone may suggest?</p>

<p>Thank you in advance</p>
