代码
复制代码 代码如下:
void getTask() {
ActivityManager activityManager;
try {
activityManager = (ActivityManager) this
.getSystemService(ACTIVITY_SERVICE);
arylistTask = new ArrayList<String>();
List<ActivityManager.RunningTaskInfo> mRunningTasks =
activityManager.getRunningTasks(30); //30表示获取的最大数
/* 以循环及baseActivity方式取得任务名称与ID */
for (RunningTaskInfo amTask : mRunningTasks)
{
Log.d("TaskInfo", amTask.baseActivity.getClassName()+"("+amTask.id+")");
}
//获取服务
List<RunningServiceInfo> mserviceTasks =
activityManager.getRunningServices(30);
/* 以循环方式取得任务名称与ID */
for (RunningServiceInfo serinfo : mserviceTasks)
{
Log.d("TaskServerInfo", serinfo.process+"("+serinfo.pid+")");
}
}
catch (Exception e)
{
}