I have an idea to make Task Manager for android.Can anyone tell me how to get all the processes currently running in android?
Asked
Active
Viewed 1.4k times
8
-
You can't. You can get all the running processes, by reading the output of `ps,` but you can't manage them, except by exec-ing other programs, which already exist. – user207421 Sep 08 '14 at 10:24
-
Possible duplicate of this Question is http://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android – Boopathi Sep 08 '14 at 10:30
1 Answers
12
using the code below you can get the list of running processes:-
ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
for(RunningAppProcessInfo runningProInfo:procInfos){
Log.d("Running Processes", "()()"+runningProInfo.processName);
}
For more information you can visit this link.
To get the application name based on package name use PackageManager
class.
final PackageManager pkgmgr = getApplicationContext().getPackageManager();
ApplicationInfo appinfo;
try {
appinfo = pkgmgr.getApplicationInfo( this.getPackageName(), 0);
} catch (final NameNotFoundException e) {
appinfo = null;
}
final String applicationName = (String) (appinfo != null ? pkgmgr.getApplicationLabel(appinfo) : "(unknown)");
To get the app name on the basis of PID use:-
public static String getAppNameByPID(Context context, int pid){
ActivityManager manager
= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for(RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()){
if(processInfo.pid == pid){
return processInfo.processName;
}
}
return "";
}
and finally to check if an app is system app or not use:-
private boolean isSystemPackage(PackageInfo pkgInfo) {
return (pkgInfo.applicationInfo.flags &
ApplicationInfo.FLAG_SYSTEM) != 0;
}

Amit Anand
- 1,225
- 1
- 16
- 40
-
-
-
-
Also it is returning package names not actual app name.Any solution? – Zaid Iqbal Sep 08 '14 at 10:50
-
1@zaidiqbal then please checkout [this answer](http://stackoverflow.com/a/12376775/3837191) – Amit Anand Sep 08 '14 at 10:52
-
-
-
-
`manager.getRunningAppProcesses()` gives a lot of tasks While `manager.getRecentTasks()` gives some tasks. **Why**? **What is difference b/w them**? – Zaid Iqbal Sep 08 '14 at 12:09
-
3`getRunningAppProcesses()` returns a list of application processes that are running on the device while `getRecentTasks(int maxNum, int flags)` returns a list of the tasks that the user has recently launched, with the most recent being first and older ones after in order. Here `maxNum`is the maximum number of entries to return in the list. The actual number returned may be smaller, depending on how many tasks the user has started and the maximum number the system can remember. – Amit Anand Sep 08 '14 at 12:19
-
-
3Note that from API 29, a regular app cannot access the list of other processes. – Alex Cohn May 24 '21 at 07:08