public class MyActivityManager extends ExpandableListActivity {
private static final String NAME = "NAME";
private static final String NO_USED = "NO_USED";
private String[] groups = { "showRecentTask", "showRunningTasks",
"showRunningAppProcesses", "showRunningServices" };
private ExpandableListAdapter mAdapter; ActivityManager mAm;
PackageManager mPM; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAm = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
mPM = this.getPackageManager(); List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>(); for (int i = 0; i < groups.length; i++) {
if (i == 0) {
showRecentTask();
} else if (i == 1) {
showRunningTasks();
} else if (i == 2) {
showRunningAppProcesses();
} else {
showRunningServices();
} Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, groups[i] + "(" + strChildren.size() + ")");
curGroupMap.put(NO_USED, ""); List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < strChildren.size(); j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, strChildren.get(j));
curChildMap.put(NO_USED, "");
}
childData.add(children);
} // Set up our adapter
mAdapter = new SimpleExpandableListAdapter(this, groupData,
android.R.layout.simple_expandable_list_item_1, new String[] {
NAME, NO_USED }, new int[] { android.R.id.text1,
android.R.id.text2 }, childData,
android.R.layout.simple_list_item_1, new String[] { NAME,
NO_USED }, new int[] { android.R.id.text1,
android.R.id.text2 });
setListAdapter(mAdapter);
} public List<String> strChildren = new ArrayList<String>(); // 最近开的task,HOME键长按会看到这个
public void showRecentTask() {
List<RecentTaskInfo> taskList = mAm.getRecentTasks(100, 0);
strChildren.clear();
for (RecentTaskInfo rti : taskList) {
ResolveInfo ri = mPM.resolveActivity(rti.baseIntent, 0);
if (ri != null) {
Log.e("showRecentTask", "" + ri.loadLabel(mPM));
strChildren.add(ri.loadLabel(mPM).toString());
}
}
} // 运行中的任务
public void showRunningTasks() {
List<RunningTaskInfo> taskList = mAm.getRunningTasks(100);
strChildren.clear();
for (RunningTaskInfo rti : taskList) {
Log.e("showRunningTasks", "Running task, numActivities="
+ rti.numActivities);
Log.e("showRunningTasks", ", description=" + rti.description);
Log.e("showRunningTasks",
", baseActivity=" + rti.baseActivity.getClassName());
Log.e("showRunningTasks",
", topActivity=" + rti.topActivity.getClassName());
strChildren.add(rti.baseActivity.getClassName());
}
} // 运行中的作为app容器的process。
public void showRunningAppProcesses() {
List<RunningAppProcessInfo> processList = mAm.getRunningAppProcesses();
strChildren.clear();
for (RunningAppProcessInfo rapi : processList) {
Log.e("showRunningAppProcesses", "" + rapi.processName);
strChildren.add(rapi.processName);
}
} // 运行中的后台服务
public void showRunningServices() {
List<RunningServiceInfo> rsiList = mAm.getRunningServices(100);
strChildren.clear();
for (RunningServiceInfo rsi : rsiList) {
Log.e("showRunningServices", "" + rsi.process);
strChildren.add(rsi.process);
}
}
}

get running task , process and service的更多相关文章

  1. Activity, Service,Task, Process and Thread之间的关系

    Activity, Service,Task, Process and Thread之间到底是什么关系呢? 首先我们来看下Task的定义,Google是这样定义Task的:a task is what ...

  2. Fixed: The Windows Process Activation Service service terminated with the following error: The system cannot find the file specified

    I'm not yet clear what I did, but I'm blogging it so it can be found if someone else has this issue. ...

  3. Hadoop:Task process exit with nonzero status of 1 异常

    在运行hadoop程序时经常遇到异常 java.io.IOException: Task process exit with nonzero status of 1.网上很多博文都说是磁盘不够的问题. ...

  4. hadoop系列 第三坑: Task process exit with nonzero status of 137

    跑MR的时候抛出异常: java.lang.Throwable: Child Error at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.j ...

  5. 2020年的UWP(2)——In Process App Service

    最早的时候App Service被定义为一种后台服务,类似于极简版的Windows Service.App Service作为Background Task在宿主UWP APP中运行,向其他UWP A ...

  6. IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页

    因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...

  7. 二分+DP HDU 3433 A Task Process

    HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  8. 为应用程序池“XX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误

    场景 WCF应用程序部署在IIS7中,使用net.tcp协议对外给几百台客户端提供服务,应用程序池不断崩溃重启. 分析过程 在事件查看器中看到的错误信息类似于 为应用程序池“XX”提供服务的进程在与 ...

  9. hadoop出现namenode running as process 18472. Stop it first.

    hadoop出现namenode running as process 18472. Stop it first.等等,类别似几个的出现. namenode running as process 32 ...

随机推荐

  1. JavaScript:隐藏Url中的参数

    <script type="text/javascript"> function submitForm(url, data) { var eleForm = docum ...

  2. CSS的单位 及 css3的calc() 及 line-height 百分比

    CSS的单位及css3的calc()及line-height百分比 摘自:http://www.haorooms.com/post/css_unit_calc 单位介绍 说到css的单位,大家应该首先 ...

  3. h5打开App的方法。

    在浏览器中: 法1: location.href = `${scheme}`;//location跳转App是几乎所以情况都支持的. 法2: var ifr = document.createElem ...

  4. Django- 反向生成url

    Django中提供了一个关于URL的映射的解决方案, 1.客户端的浏览器发起一个url请求,Django根据URL解析,把url中的参数捕获,调用相应的试图,获取相应的数据,然后返回给客户端显示 2. ...

  5. a4纸尺寸像素大小

    A4纸尺寸:210mm*297mm,也就是21.0cm*29.7cm,而1英寸=2.54cm.如果在PS中新建为72像素/英寸的画布,大小为A4尺寸,经过换算就是:(72px/2.54cm) = 28 ...

  6. 登录用户执行sudo时报错

    场景: 以普通用户登录,登陆后切换至root或其他用户时报错(sudo su -或sudo -i) 报错信息: -bash: /bin/logger: Argument list too long 根 ...

  7. 强大的jQuery幻灯片播放插件 支持全拼、拖拽和下载等功能

    在线演示 本地下载

  8. Android Studio Gradle Could not reserve enough space for object heap

    Studio 创建第一个工程报错 Error:Unable to start the daemon process.This problem might be caused by incorrect ...

  9. 华为S5700系列交换机配置通过流策略实现VLAN间三层隔离

    组网图形 图1 配置通过流策略实现VLAN间三层隔离组网图 组网需求 如图一所示,为了通信的安全性,某公司将访客.员工.服务器分别划分到VLAN10.VLAN20.VLAN30中.公司希望: 员工.服 ...

  10. [翻译]在gulp构建工具中使用PostCSS

    前言 PostCSS已经在一段时间内迅速普及,如果你还不知道PostCSS或还没有使用它,我建议你看一下之前的一篇介绍文章<PostCSS简介>,其中介绍了使用PostCSS的基本方法,包 ...