请帮我更改Android L的代码。在API 21中不推荐使用函数getRunningTask
。
ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (RunningTaskInfo task : tasks) {
if (ctx.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
return true;
}
答案 0 :(得分:0)
使用此代码:
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> alltasks= activityManager.getAppTasks();
for (ActivityManager.AppTask task : alltasks) {
Log.d(TAG, "stackId: " + task.getTaskInfo().stackId);
}