如何获取正在运行任务的列表

来自:http://wiki.forum.nokia.com/index.php/%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%E4%BB%BB%E5%8A%A1%E7%9A%84%E5%88%97%E8%A1%A8

  • 设备, 软件 版本:

S60 1st Edition S60 2nd Edition and FP1, FP2, FP3 S60 3rd Edition and FP1

Series 80 2nd Edition


  • 详细描述:

描述

Symbian操作系统的应用程序框架提供了一组API用以获得当前正在运行的任务的信息(无论其在前台或后台运行)。


 解决方案

我们可以使用TApaTaskList获取当前正在运行的任务的列表。具体任务是通过正在运行的程序window group来识别的,在构造TApaTaskList时我们需要将window server的session作为参数传递进去。

 
  
  
#include  < apgtask.h >      //  link against apgrfx.lib
 
    TApaTaskList tasklist(CCoeEnv::Static()
-> WsSession());
 
    TApaTask taskInForeground 
=  tasklist.FindByPos(  0  );
 
    
//  Window Group ID of the foreground task
 
    TInt WindowGroupIdentifier 
=  taskInForeground.WgId();
 
    
//  Thread ID of the foreground task
 
    TThreadId ThreadIdentifier 
=  taskInForeground.ThreadId();


TApaTaskList中第一个任务是在前台运行的那个(相关window group位置顺序是从0开始的)

TApaTask包括很多与task相关的有用信息,如线程标识(ThreadId())以及window group标识(WgId()).

此外,还有一些有用的函数,如EndTask(),用来请求某任务的正常关闭,以及KillTask()用来直接中止某任务。

SendToBackground()以及BringToForeground()方法可以用来控制程序在任务列表中的位置。 

猜你喜欢

转载自blog.csdn.net/windcao/article/details/1804523