0

Some applications in Android show the number of background applications running in the device. Is there any way to find it programmatically ?

Tomin Jacob
  • 333
  • 1
  • 9
  • 24

1 Answers1

1

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)

Bradley Campbell
  • 9,298
  • 6
  • 37
  • 47
  • How should I implement it as a program ? Suppose I need to display the count in a textview. – Tomin Jacob Sep 30 '14 at 03:38
  • ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); TextView t = new TextView(context); t.setText(""+activityManager.getRunningTasks(100)); – Bradley Campbell Sep 30 '14 at 03:41
  • 1
    Note: it also doesn't work on the upcoming [Android L](http://developer.android.com/preview/api-overview.html#BehaviorGetRecentTasks) release, which deprecates the method and `getRunningTasks` will only returning task from your application and possibly the Home (launcher) application. – ianhanniballake Sep 30 '14 at 03:55
  • I did not know this. All the more reasons to not use it :) – Bradley Campbell Sep 30 '14 at 03:56
  • @ianhanniballake So what method should be used instead of the deprecated one ? – Tomin Jacob Sep 30 '14 at 07:19
  • The note on the [related Android issue](https://code.google.com/p/android-developer-preview/issues/detail?id=29#c50) states "we hope to expose the system’s internal usage stats service in a new and expanded form that is available to third party apps through the SDK." - although no details on said API are yet available beyond that comment. – ianhanniballake Sep 30 '14 at 15:53