Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.app.ActivityManager; import android.app.ActivityManager.AppTask; import android.app.ActivityManager.RecentTaskInfo; import android.content.Intent; import android.util.Log; import java.util.List; public class Main { public static final String TAG = "DocumentUtilities"; private static Intent finishAndRemoveTasks(List<ActivityManager.AppTask> tasksToFinish) { Intent removedIntent = null; for (ActivityManager.AppTask task : tasksToFinish) { Log.d(TAG, "Removing task with duplicated data: " + task); removedIntent = getBaseIntentFromTask(task); task.finishAndRemoveTask(); } return removedIntent; } /** * Returns the baseIntent of the RecentTaskInfo associated with the given task. * @param task Task to get the baseIntent for. * @return The baseIntent, or null if it couldn't be retrieved. */ public static Intent getBaseIntentFromTask(AppTask task) { RecentTaskInfo info = getTaskInfoFromTask(task); return info == null ? null : info.baseIntent; } /** * Returns the RecentTaskInfo for the task, if the ActivityManager succeeds in finding the task. * @param task AppTask containing information about a task. * @return The RecentTaskInfo associated with the task, or null if it couldn't be found. */ public static RecentTaskInfo getTaskInfoFromTask(AppTask task) { RecentTaskInfo info = null; try { info = task.getTaskInfo(); } catch (IllegalArgumentException e) { Log.e(TAG, "Failed to retrieve task info: ", e); } return info; } }