Accessing the Running Applications

Applications running on a device are known as tasks. The TApaTaskList class is used to access applications running on a device, where each task can be an instance of the TApaTask class, which is used to manipulate or query tasks.

Finding an application by its UID

The following example code shows how to find or end a running application that is, a task by its UID using the TApaTaskList and TApaTask classes.

// Assign UID of the application to a constant, to find the application by its UID

const TUid KMyAppUid = {0x10009e9f};

// Creates an instance of a TApaTaskList taking reference to a window server session.
//    TApaTaskList allows access to all tasks running on the device. 
             
TApaTaskList taskList(CCoeEnv::Static()->WsSession());

// Creates a TApaTask instance that allows us to find out things about the task in question, for example: send a
// key-stroke to it, abort or end the task.              

TApaTask task = taskList.FindApp(KMyAppUid);

// Checks whether the specified task exists on the device.          

if (task.Exists())
    {
    task.EndTask(); // Ends the task
    }

Bringing an application to the foreground

The following code example shows how to find an application by its name and then bring it to the foreground.

_LIT(KAppName, "myApp");
TApaTaskList taskList(CCoeEnv::Static()->WsSession());
TApaTask task = taskList.FindApp(KAppName);
if (task.Exists())
    {
    task.BringToForeground();
    }