title: Detecting android Activity launches
body: <p>I have searched the stackoverflow for this question and found :
  <a href="https://stackoverflow.com/questions/3290936/android-detect-when-other-apps-are-launched">Android, Detect when other apps are launched</a> and 
  <a href="https://stackoverflow.com/questions/12072135/reliable-way-to-detect-application-launch-from-home-desktop">Reliable way to detect application launch from home / desktop?</a> , which kind of answers my question but it's still not enough.</p>
  
  <p><strong>What I want to do</strong>
  I want to create a widget/app that shows the user of the device a list of recent apps and a list of most used apps.</p>
  
  <p><strong>Problem</strong>
  How can I have accurate data about the apps in order to build a list of most used apps.</p>
  
  <p><strong>Base information</strong></p>
  
  <ul>
  <li>I am compiling my own Android OS (4.2 based) code so I have access to
  everything.</li>
  <li>I am developing the launcher as well.</li>
  <li>It needs to pass the CTS and be Google approved.</li>
  <li>I can make the app with system privileges.</li>
  <li>I know that this might be a security issue for Google.</li>
  </ul>
  
  <p><strong>Some solutions</strong></p>
  
  <p>The recent apps can be found via ActityManager, getRecentApps method, so now problem there. </p>
  
  <p>I have searched the web for this and already found the following solutions:</p>
  
  <ol>
  <li>Use a service to query the activityManager, getRunningTasks method every X seconds and build the list ( innacurate information, also using a lot of batery ). </li>
  <li>Use the logcat to get this information (seems like a hack to me, needs system permissions)</li>
  <li>Change the activityManager itself in order to provide this information (will most likely fail the CTS tests)</li>
  <li>Use the launcher to verify the apps that were launched (misses the apps launched inside other apps)</li>
  </ol>
  
  <p>Anything else I have missed?</p>
  
  <p>Thanks in advance,
  Tiago Costa</p>