title: How to kill currently running task in android
body: <p>I am trying to  build  a task killer type of app in android. I can show the list of currently running task using <strong>ActivityManager</strong> but facing problem in killing the task.</p>
  <p>Here is what i am doing to get the list of currently running task :</p>
  <pre><code>ActivityManager am = (ActivityManager) context.
              getSystemService(Activity.ACTIVITY_SERVICE);
  List&lt;RunningTaskInfo&gt; a = am.getRunningTasks(Integer.MAX_VALUE);
  
  PackageManager pack = this.getPackageManager();
  
  for(int i = 0; i &lt; a.size(); i++) {
      String packageName = a.get(i).topActivity.getPackageName();
      Drawable d = null;
      String appName = &quot;&quot;;
  
      try {
          d = pack.getApplicationIcon(packageName);
          appName = (String)pack.getApplicationLabel(pack.getApplicationInfo(packageName,PackageManager.GET_META_DATA));
      } catch (NameNotFoundException e) {
          e.printStackTrace();
      }
      
      packName.add(packageName);  //arraylist of package name
      apps.add(appName);          // arraylist of app name
      icons.add(d);               //arraylist of icons
  }
  </code></pre>
  <p>It worked for me But now as I am trying to kill the task using  killBackgroundProcesses :</p>
  <pre><code>am.killBackgroundProcesses(package name);
  </code></pre>
  <p>It did not work . Also <strong>killBackgroundProcesses</strong> method is available in API level 2.2  then how can i perform the same task in previous API level such as 1.6 etc.</p>
  <p>Is there any other way to show the currently active apps and kill them?</p>