0

I have been trying to get the number of applications currently running in the background using the following code:

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcessInfo = am.getRunningAppProcesses();
int numberOfApps =  runningAppProcessInfo.size();

But even though more than 1 application is running in the background the code is returning 1.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
Shashank
  • 82
  • 1
  • 1
  • 9
  • Yeah, but you need a scary permission for your app in order to do it (http://developer.android.com/reference/android/Manifest.permission.html#GET_TASKS). Edit: this is scary because it is a permission that most apps shouldn't need, and from a user standpoint makes your app considerably less trustworthy unless you have a very obvious reason for needing it. The method to achieve what you are after is: http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks(int) – Jigar Mar 15 '16 at 11:56
  • but this method is deprecated for lollipop.is there any other solution? – Shashank Mar 15 '16 at 12:36

0 Answers0