To get a running task, you first need to declare an active object Manager (Activitymanager) that all active tasks belong to this, and then you can get all the active objects by getting the service, and then you can get all the tasks and services that are running through the active object. Of course to get services and tasks is to use a different approach, but the same way. Here is the get code:
Code
Copy Code code as follows:
void Gettask () {
Activitymanager Activitymanager;
try {
Activitymanager = (Activitymanager) This
. Getsystemservice (Activity_service);
Arylisttask = new arraylist<string> ();
List<activitymanager.runningtaskinfo> Mrunningtasks =
Activitymanager.getrunningtasks (30); 30 indicates the maximum number obtained
* * To get the task name and ID in a circular and baseactivity manner.
for (Runningtaskinfo amtask:mrunningtasks)
{
LOG.D ("TaskInfo", AmTask.baseActivity.getClassName () + "(" +amtask.id+ ")");
}
Get a service
List<runningserviceinfo> Mservicetasks =
Activitymanager.getrunningservices (30);
* * To get the task name and ID in a circular manner.
for (Runningserviceinfo serinfo:mservicetasks)
{
LOG.D ("Taskserverinfo", serinfo.process+ "(" +serinfo.pid+ ")");
}
}
catch (Exception e)
{
}