android将后台应用置顶及moveTaskToFront的用法

private void bring2Front()
    {
        ActivityManager activtyManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        List runningTaskInfos = activtyManager.getRunningTasks(3);
        for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos)
        {
            if (this.getPackageName().equals(runningTaskInfo.topActivity.getPackageName()))
            {
                activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME);
                return;
            }
        }
    }

参考https://www.programcreek.com/java-api-examples/?class=android.app.ActivityManager&method=moveTaskToFront

你可能感兴趣的:(android,java)