I need to get the list of running apps(apps that you see when you click on "recent apps" button). Below is the function I'm using to check whether an app running in background
boolean isNamedProcessRunning(String packageName){
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
for (int i = 0; i < runningAppProcessInfo.size(); i++) {
Log.e("", "---> running "+runningAppProcessInfo.get(i).processName);
if(runningAppProcessInfo.get(i).processName.equals(packageName)) {
return true;
}
}
return false;
}
Everything seemed to be fine until I tried "Chrome" app. For instance, I opened chrome and closed by using home button. And I could see "Chrome" on "app history" / "running apps" list. And I swiped away chrome from there. Still the above code says "Chrome" is running on background. How can I solve this?