Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

判断一个应用是否在前台代码库有问题? #16

Open
XiongKe94 opened this issue Dec 1, 2016 · 1 comment
Open

判断一个应用是否在前台代码库有问题? #16

XiongKe94 opened this issue Dec 1, 2016 · 1 comment

Comments

@XiongKe94
Copy link

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,
    就是说的你的代码判断不准确
@XiongKe94
Copy link
Author

我也向作者提问了,如果这个APP,弹出通知,下载进度等,返回结果就是这个应用在前台,其实该应用在后台。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant