@Override
public void onClick(View v) {
String info = "";
List<RunningTaskInfo> runningTasks = am.getRunningTasks(maxNum);
for (RunningTaskInfo task:runningTasks){
info += "一个任务信息开始:\n";
info += "启动当前任务的activity名称:" + task.baseActivity.getClassName()+ "\n";
info += "当前任务状态的描述:" + task.description.toString()+ "\n";
info += "当前任务Id:" + task.id+ "\n";
info += "任务中所运行的Activity数量,包含已停止的:" + task.numActivities+ "\n";
info += "任务中所运行的Activity数量,不包含已停止或不延续运行的:" + task.numRunning+ "\n";
System.out.print(info);
}
}
服务获取信息
@Override
public void onClick(View v) {
String info = "";
List<RunningServiceInfo> serivces = am.getRunningServices(maxNum);
for (RunningServiceInfo service:serivces){
info = "一个service信息开始:\n";
info += "服务第一次被激活的时间:" + service.activeSince + "\n";
info += "接到该服务的客户端数目:" + service.clientCount+ "\n";
info += "服务运行期间,出现死机的次数:" + service.crashCount+ "\n";
info += "若为true,则该服务在后台执行:" + service.foreground+ "\n";
info += "最后一个Activity与服务绑定的时间:" + service.lastActivityTime+ "\n";
info += "正在运行服务的Id:" + service.pid+ "\n";
info += "该服务的名称:" + service.process+ "\n";
info += "服务的组件名称:" + service.service+ "\n";
info += "若此值为true,则表示服务已经在启动运行中:" + service.started+ "\n";
info += "若此值不为0,则表示该服务不在运行中,将在参数给定的时间点重启服务:" + service.restarting+ "\n";