Get Recent and Running application list not processes

pyus13 picture pyus13 · Sep 11, 2012 · Viewed 7.3k times · Source

I tried a lot to get the list of recent and running applications(not processes) but couldn't get it.

I went through all the stackoverflow questions regarding this but the only answer i got about the running processes and recent tasks not the application specific like we can see in Samsung Mobile task manager on long press of home button.

I am able to get the Running processes by this code :

ActivityManager actvityManager = (ActivityManager)
this.getSystemService( ACTIVITY_SERVICE );
List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();

for(RunningAppProcessInfo runningProInfo:procInfos){

        Log.d("Running Processes", "()()"+runningProInfo.processName);
}

It is giving the package names of all processes but i want only the package names of applications that i have launched(Both Recent and Running).

How can I extract that from Running Application Processes?

Answer

Michael Celey picture Michael Celey · Sep 11, 2012

UPDATE: I don't see a way to get the name of the recent tasks even by using the below solution but this will work for the currently running and frozen tasks: getRunningTasks

Using getRunningTasks will return a list of RunningTaskInfo that contain the base ComponentName which you can use to get the package name from by calling getPackageName().

ORIGINAL ANSWER:

You should look into getRecentTasks. Its function is described as

Return a list of the tasks that the user has recently launched, with the most recent being first and older ones after in order.

Note: this method is only intended for debugging and presenting task management user interfaces.

This should get you a list of all the apps that have recently run or are running.