\frameworks\base\packages\SystemUI\src\com\android\systemui\recent\RecentsPanelView.java
public voiddeleteAllRecent(){
final ActivityManager am = (ActivityManager)
mContext.getSystemService(Context.ACTIVITY_SERVICE);
if (am != null) {
for(TaskDescription recent :mRecentTaskDescriptions){
am.removeTask(recent.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
}
}
if(mRecentTaskDescriptions!=null){
mRecentTaskDescriptions.clear();
if (mRecentTasksLoader.getLoadedTasks() !=null){
mRecentTasksLoader.getLoadedTasks().clear();
}
dismissAndGoBack();
}
}
public static void delAllRecentTask(Contextcontext){
Log.i("zhangliang=>1","delAllRecentTask");
final ActivityManager am =(ActivityManager)
context.getSystemService(Context.ACTIVITY_SERVICE);
if(mRecentTaskDescriptions==null){
mRecentTaskDescriptions = new ArrayList<TaskDescription>();
mRecentTaskDescriptions=getTaskInRecentList(context);
}
for(TaskDescription recent :mRecentTaskDescriptions){
if(!recent.packageName.toString().equals("com.snowfish.aios.launcher")&&!recent.packageName.toString().equals("com.jeejen.family")){
am.removeTask(recent.persistentTaskId,ActivityManager.REMOVE_TASK_KILL_PROCESS);
}
}
if(mRecentTaskDescriptions!=null){
mRecentTaskDescriptions.clear();
if(RecentTasksLoader.getInstance(context).getLoadedTasks()!= null){
RecentTasksLoader.getInstance(context).getLoadedTasks().clear();
}
}
// dismissActivityGoBack(context);
}
//自定一个一个广播通知去清除所有的Task
frameworks\base\packages\SystemUI\src\com\android\systemui\recent\DeleteTaskReceiver.java
public classDeleteTaskReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent) {
if("CLEAR_ALL_TASK".equals(intent.getAction())){
RecentsPanelView.delAllRecentTask(context);
}
通过发送上面那个广播过去即可