title: Alert user when they open a preselected app
body: <p>I'm relatively new to Android development and am trying to display a prompt to the user whenever they navigate away from the app and try to run a different pre-selected app. I'm aware that I can't detect the start up but I believe I can view the active app with the following:</p>
  
  <pre><code>ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
  List&lt;ActivityManager.RunningAppProcessInfo&gt; runningAppProcessInfo = am.getRunningAppProcesses();
  
  for (int i = 0; i &lt; runningAppProcessInfo.size(); i++) {
    if(runningAppProcessInfo.get(i).processName.equals("com.the.app.you.are.looking.for" &amp;&amp; disabled == true) {
      // Display overlaying message to users!
    }
  }
  </code></pre>
  
  <p>1st question: How can I get this code to be checked many times a second like in a polling event? Would I use an Async Task or a Background Service and how would I communicate with it to update the <code>disabled</code> boolean?</p>
  
  <p>2nd question: Should the message I display to the user be a SYSTEM_ALERT_WINDOW or something else so as to overlay all active apps?</p>