title: Android - How to detect when 3d party app is starting
body: <p>I'm currently developing an app for tablets which will show commercials in stores. I need to add a password protection for the settings application. To achieve this I need to detect that the settings app is started in a background service. For devices with Android below API 21 this can be done with <a href="http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks%28int%29" rel="nofollow noreferrer">getRunningTasks()</a>. Unfortunately this method is deprecated now. I tried achieving my goal with <a href="https://stackoverflow.com/questions/3290936/android-detect-when-other-apps-are-launched">this answer</a>, but things aren't working as I need. I'm trying to listen for <code>V/WindowManager(  740): Adding window Window{1f4535ef u0 com.android.settings/com.android.settings.Settings} at 9 of 16 (before Window{e14eed2 u0 Starting com.android.settings})</code> but I can't see it as an output. I'm using the code from the answer I referenced above. Instead of Toasting it I'm printing it in the logcat. </p>
  
  <p>Can you tell me how my goal can be achieved for android versions above API 21? I know it is possible because apps like Smart AppLock does it. Thanks in advance!</p>