title: How to close all Recent App through my app programmatically in android
body: <p>I'm designing an application for removing recent tasks. and i use this code for remove recent tasks,</p>
  
  <pre><code>public boolean removeTask(int taskId, int flags) {
      try {
          return (Boolean) mRemoveTask.invoke(mActivityManager, Integer.valueOf(taskId), Integer.valueOf(flags) );
      } catch (Exception ex) {
          Log.i("MyActivityManager", "Task removal failed", ex);
      }
      return false;
  }
  
  public void clearRecentTasks() {
      List&lt;ActivityManager.RecentTaskInfo&gt; recents = mActivityManager.getRecentTasks(1000, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
      // Start from 1, since we don't want to kill ourselves!
      for( int i=1; i &lt; recents.size(); i++ ) {
          removeTask( recents.get(i).persistentId, 0);
      }
  }
  </code></pre>