Created
February 28, 2023 02:32
-
-
Save EHG613/6a6dc4b860b926e5916ae109b9cdf9cd to your computer and use it in GitHub Desktop.
GET_TASKS权限在5.0已废弃;可以通过如下方式获取任务栈列表
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Log.e("Live",getTaskId()+""); | |
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { | |
ActivityManager activityManager = getSystemService(ActivityManager.class); | |
//获取任务栈列表 | |
List<ActivityManager.AppTask> tasks = activityManager.getAppTasks(); | |
for (ActivityManager.AppTask task : tasks) { | |
ActivityManager.RecentTaskInfo info = task.getTaskInfo(); | |
int activityCount = info.numActivities; //栈内Activity数量 | |
String topActivity = info.topActivity.getClassName(); //栈顶Activity | |
String baseActivity = info.baseActivity.getClassName(); //栈底Activity | |
Log.e("Live",activityCount+";"+topActivity+";"+baseActivity+";"+info.affiliatedTaskId); | |
// task.setExcludeFromRecents(true); //不显示在最近任务列表中 | |
// task.finishAndRemoveTask(); //销毁任务栈内全部Activity | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment