Tasks (running GUI application), how to find them

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: symbianyucca (30 Mar 2007)
Last edited: hamishwillee (12 Jan 2012)

Following GetTasksL()-function illustrates how to get all running GUI application and their information. Note that if you are running this inside a application that is not implementing standard application framework, you have the replace the RWsSession handling.

If you are interested on finding other than GUI tasks, you could utilize the process finding example code better.

void GetTasksL(void)
RWsSession& wsSession = CEikonEnv::Static()->WsSession();
CApaWindowGroupName* wgName=CApaWindowGroupName::NewL(wsSession);
CArrayFixFlat<TInt>* WindowGroupIds = new(ELeave)CArrayFixFlat<TInt>(1);
const TInt count = WindowGroupIds->Count();
for (TInt ii=0; ii<count; ii++)
TInt wgId = WindowGroupIds->At(ii);
CleanupStack::PopAndDestroy(2);//WindowGroupIds, wgName

Then if you are interested to find just one specific task, and you know the application UID you could also use the code shown in the following example function:

void DoSomethingWithTaskL(TUid aUid)
RWsSession& wsSession = CEikonEnv::Static()->WsSession();
TApaTaskList taskList( wsSession );
TApaTask task = taskList.FindApp(aUid);
if( task.Exists() )
//RThread th;
//if (t.Open(task.ThreadId())==KErrNone)
// th.Kill(0);
// th.Close();

The DoSomethingWithTaskL() example function shows different approaches you could use for closing GUI application from other processes, note that in S60 3rd Edition some of the ways might require some capabilities. Also the nicest way is always to ask nicely, thus the EndTask() should nearly always be used, it basically sends the exit command to the application, so the application to be closed can handle its data saving etc. when exiting.

Finding an application by its UID ( 3rd Edition )

//  Constant the UID of the application that we are trying to find. 
const TUid KMyAppUid = {0x10009e9f};
// Gets a reference to a window server session
TApaTaskList taskList(CCoeEnv::Static()->WsSession());
// Create TApaTask instance
TApaTask task = taskList.FindApp(KMyAppUid);
if (task.Exists())
// Do Something

The following libraries need to be added in the MMP configuration file. apgrfx.lib, ws32.lib

Internal links

This page was last modified on 12 January 2012, at 07:08.
40 page views in the last 30 days.