title: how to check the top activity from android app in background service
body: <p>In my app i want to check whethere any other app launches or not from my app.So i am currently usimg Activitymanager to find the top activity like this  </p>
  
  <pre><code>ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
  List&lt; ActivityManager.RunningTaskInfo &gt; taskInfo = am.getRunningTasks(1);
  Log.d("topActivity", "CURRENT Activity ::"
           + taskInfo.get(0).topActivity.getClassName());
  ComponentName componentInfo = taskInfo.get(0).topActivity;
  componentInfo.getPackageName();
  </code></pre>
  
  <p>But i want to run this code in background service.So that i can detect When other app launches through this.So is there any idea to do this.Plz help me.thanks</p>