0

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?

Manu
  • 379
  • 2
  • 16

1 Answers1

0

KillProcess only can kill that process. otherwise it will be listed in getRunningAppProcesses()

Please check this answer

https://stackoverflow.com/a/11865184/3020568

Community
  • 1
  • 1
Deniz
  • 12,332
  • 10
  • 44
  • 62