public static boolean isAppForegroundRunning(final Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (activityManager == null) return false; List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (topActivity.getPackageName().equals(context.getPackageName())) { return true; } } return false; } - 手机系统:Android 4.3 - 型号:Galaxy Nexus - 你的代码:`AndroidProcesses.getRunningForegroundApps(context);` 如果一个应用退出到后台,但是正在下载文件的话,`AndroidProcesses.getRunningForegroundApps(context);`中的`foreground==true,`而以前使用的代码返回值为false, 就是说的你的代码判断不准确
Activity
XiongKe94 commentedon Dec 1, 2016
我也向作者提问了,如果这个APP,弹出通知,下载进度等,返回结果就是这个应用在前台,其实该应用在后台。