当前位置: 首页>>代码示例>>Java>>正文


Java ActivityManager.getAppTasks方法代码示例

本文整理汇总了Java中android.app.ActivityManager.getAppTasks方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.getAppTasks方法的具体用法?Java ActivityManager.getAppTasks怎么用?Java ActivityManager.getAppTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.ActivityManager的用法示例。


在下文中一共展示了ActivityManager.getAppTasks方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeNonVisibleChromeTabbedRecentEntries

import android.app.ActivityManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();

    Context context = ContextUtils.getApplicationContext();
    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    PackageManager pm = getPackageManager();

    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        String className = DocumentUtils.getTaskClassName(task, pm);

        // It is not easily possible to distinguish between tasks sitting on top of
        // ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
        // close them to be on the cautious side of things.
        if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
                || TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
                && !visibleTaskIds.contains(info.id)) {
            task.finishAndRemoveTask();
        }
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:25,代码来源:IncognitoNotificationService.java

示例2: IsBaseActivityRunning

import android.app.ActivityManager; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public boolean IsBaseActivityRunning() {
    ActivityManager activityManager = (ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE);

    if (activityManager == null) {
        Logger.getInstance().Error(TAG, "ActivityManager is null!");
        return false;
    }

    List<ActivityManager.AppTask> tasks = activityManager.getAppTasks();

    for (ActivityManager.AppTask task : tasks) {
        if (_context.getPackageName().equalsIgnoreCase(task.getTaskInfo().baseActivity.getPackageName())) {
            return true;
        }
    }

    return false;
}
 
开发者ID:GuepardoApps,项目名称:LucaHome-AndroidApplication,代码行数:20,代码来源:AndroidSystemController.java

示例3: getTasksFromRecents

import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public List<Entry> getTasksFromRecents(boolean isIncognito) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<Entry> entries = new ArrayList<Entry>();
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (!isValidActivity(isIncognito, intent)) continue;

        int tabId = getTabIdFromIntent(intent);
        if (tabId == Tab.INVALID_TAB_ID) continue;

        String initialUrl = getInitialUrlForDocument(intent);
        entries.add(new Entry(tabId, initialUrl));
    }
    return entries;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:20,代码来源:ActivityDelegateImpl.java

示例4: onTaskRemoved

import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public void onTaskRemoved(Intent rootIntent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager am = (ActivityManager) mContext.getSystemService(
                Context.ACTIVITY_SERVICE);
        List<ActivityManager.AppTask> tasks = am.getAppTasks();
        // In multi-window case, there could be multiple tasks. Only swiping away the last
        // activity should be pause the notification.
        if (tasks.size() > 0) return;
    }
    // This funcion is called when Chrome is swiped away from the recent apps
    // drawer. So it doesn't catch all scenarios that chrome can get killed.
    // This will only help Android 4.4.2.
    onBrowserKilled();
    mStopPostingProgressNotifications = true;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:17,代码来源:DownloadNotificationService.java

示例5: isParentInAndroidOverview

import android.app.ActivityManager; //导入方法依赖的package包/类
/** If the API allows it, returns whether a Task still exists for the parent Activity. */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean isParentInAndroidOverview() {
    ActivityManager activityManager = (ActivityManager) mTab.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent taskIntent = DocumentUtils.getBaseIntentFromTask(task);
        if (taskIntent != null && taskIntent.filterEquals(mTab.getParentIntent())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:14,代码来源:TabWebContentsDelegateAndroid.java

示例6: finishOtherTasksWithData

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * Finishes tasks other than the one with the given ID that were started with the given data
 * in the Intent, removing those tasks from Recents and leaving a unique task with the data.
 * @param data Passed in as part of the Intent's data when starting the Activity.
 * @param canonicalTaskId ID of the task will be the only one left with the ID.
 * @return Intent of one of the tasks that were finished.
 */
public static Intent finishOtherTasksWithData(Uri data, int canonicalTaskId) {
    if (data == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return null;

    String dataString = data.toString();
    Context context = ContextUtils.getApplicationContext();

    ActivityManager manager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> tasksToFinish = new ArrayList<ActivityManager.AppTask>();
    for (ActivityManager.AppTask task : manager.getAppTasks()) {
        RecentTaskInfo taskInfo = getTaskInfoFromTask(task);
        if (taskInfo == null) continue;
        int taskId = taskInfo.id;

        Intent baseIntent = taskInfo.baseIntent;
        String taskData = baseIntent == null ? null : taskInfo.baseIntent.getDataString();

        if (TextUtils.equals(dataString, taskData)
                && (taskId == -1 || taskId != canonicalTaskId)) {
            tasksToFinish.add(task);
        }
    }
    return finishAndRemoveTasks(tasksToFinish);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:32,代码来源:DocumentUtils.java

示例7: excludeFromTaskList

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * Exclude the app from the recent tasks list.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void excludeFromTaskList() {
    ActivityManager am = (ActivityManager) getActivity()
            .getSystemService(Context.ACTIVITY_SERVICE);

    if (am == null || Build.VERSION.SDK_INT < 21)
        return;

    List<AppTask> tasks = am.getAppTasks();

    if (tasks == null || tasks.isEmpty())
        return;

    tasks.get(0).setExcludeFromRecents(true);
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:19,代码来源:BackgroundExt.java

示例8: getTopActivityByActivityManager

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 通过ActivityManager拿到栈顶Activity的ClassName,然后跟列表中的Activity比对,获取栈顶Activity。
 * 注意:这种方式有个很严重的缺陷,如果某个Activity在栈里多次出现将导致判断错误,这时候将返回null。
 * 可靠性相对一般,不会返回错误结果。
 *
 * @param application application
 * @param activities  所有的Activity列表
 * @return 栈顶Activity,获取不到的时候将返回null,不会返回错误结果。
 * @throws ReflectUtils.ReflectException 可能会发生异常,强制要求处理异常情况。
 */
public static Activity getTopActivityByActivityManager(Context application
        , List<Activity> activities) throws ReflectUtils.ReflectException {
    ActivityManager activityManager = (ActivityManager) application
            .getSystemService(Context.ACTIVITY_SERVICE);
    String topActivity = null;
    String packageName = application.getPackageName();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
        for (int i = 0, size = appTasks.size(); i < size; i++) {
            ActivityManager.RecentTaskInfo taskInfo = appTasks.get(size - 1 - i).getTaskInfo();
            if (packageName.equals(taskInfo.baseActivity.getPackageName())) {
                topActivity = taskInfo.topActivity.getClassName();
            }
        }
    }
    if (TextUtils.isEmpty(topActivity)) {
        Log.i(TAG, "尝试通过getTopActivityByActivityManager获取Activity失败");
        return null;
    }

    boolean check = false;
    Activity result = null;
    if (activities != null) {
        for (Activity activity : activities) {
            if (topActivity.equals(activity.getClass().getName())) {
                if (check) {
                    // 出现重复Activity,返回null
                    Log.i(TAG, "尝试通过getTopActivityByActivityManager获取Activity失败");
                    return null;
                }
                check = true;
                result = activity;
            }
        }
    }
    if (result == null) {
        Log.w(TAG, "尝试通过getTopActivityByActivityManager获取Activity失败");
    } else {
        Log.i(TAG, "尝试通过getTopActivityByActivityManager获取Activity成功");
    }
    return result;
}
 
开发者ID:aesean,项目名称:ActivityStack,代码行数:53,代码来源:ApplicationUtils.java

示例9: finishAndRemoveTaskIfInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
private void finishAndRemoveTaskIfInBackground() {
    if (activitiesInStartedState == 0) {
        final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (activityManager == null) {
            return;
        }

        for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
            task.finishAndRemoveTask();
        }
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:13,代码来源:VisibilityLifeCycleCallback.java

示例10: quitApp

import android.app.ActivityManager; //导入方法依赖的package包/类
public static void quitApp(final Context context) {
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager am = (ActivityManager) context.getSystemService("activity");
        List appTasks = am.getAppTasks();
        Iterator i$ = appTasks.iterator();

        while (i$.hasNext()) {
            ActivityManager.AppTask appTask = (ActivityManager.AppTask) i$.next();
            appTask.finishAndRemoveTask();
        }

        Process.killProcess(Process.myPid());
        am.killBackgroundProcesses(context.getPackageName());
        System.exit(0);
    } else if (Build.VERSION.SDK_INT >= 11) {
        Intent activityManager = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        activityManager.addFlags('喜');
        activityManager.addFlags(268435456);
        activityManager.addFlags(67108864);
        activityManager.addFlags(65536);
        activityManager.addFlags(8388608);
        context.startActivity(activityManager);
        (new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
            public void run() {
                Process.killProcess(Process.myPid());
                System.exit(0);
            }
        }, 300L);
    } else {
        Process.killProcess(Process.myPid());
        ActivityManager activityManager1 = (ActivityManager) context.getSystemService("activity");
        activityManager1.killBackgroundProcesses(context.getPackageName());
        System.exit(0);
    }

}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:37,代码来源:AppExitUtil.java

示例11: isMergedInstanceTaskRunning

import android.app.ActivityManager; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private boolean isMergedInstanceTaskRunning() {
    if (!FeatureUtilities.isTabModelMergingEnabled() || sMergedInstanceTaskId == 0) {
        return false;
    }

    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (AppTask task : manager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        if (info.id == sMergedInstanceTaskId) return true;
    }
    return false;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:15,代码来源:ChromeTabbedActivity.java

示例12: getTask

import android.app.ActivityManager; //导入方法依赖的package包/类
private ActivityManager.AppTask getTask(boolean isIncognito, int tabId) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        int taskId = getTabIdFromIntent(intent);
        if (taskId == tabId && isValidActivity(isIncognito, intent)) return task;
    }
    return null;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:12,代码来源:ActivityDelegateImpl.java

示例13: isIncognitoDocumentAccessibleToUser

import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public boolean isIncognitoDocumentAccessibleToUser() {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (isValidActivity(true, intent)) return true;
    }
    return false;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:13,代码来源:ActivityDelegateImpl.java

示例14: getLargestTaskIdFromRecents

import android.app.ActivityManager; //导入方法依赖的package包/类
private int getLargestTaskIdFromRecents() {
    int biggestId = Tab.INVALID_TAB_ID;
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
        if (info == null) continue;
        biggestId = Math.max(biggestId, info.persistentId);
    }
    return biggestId;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:13,代码来源:DocumentTabModelSelector.java

示例15: finishAllDocumentActivities

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * Finishes all DocumentActivities that appear in Android's Recents.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void finishAllDocumentActivities() {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager activityManager =
            (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    for (ActivityManager.AppTask task : activityManager.getAppTasks()) {
        Intent intent = DocumentUtils.getBaseIntentFromTask(task);
        if (isValidActivity(false, intent) || isValidActivity(true, intent)) {
            task.finishAndRemoveTask();
        }
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:17,代码来源:ActivityDelegate.java


注:本文中的android.app.ActivityManager.getAppTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。