get running task , process and service
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的更多相关文章
- Activity, Service,Task, Process and Thread之间的关系
Activity, Service,Task, Process and Thread之间到底是什么关系呢? 首先我们来看下Task的定义,Google是这样定义Task的:a task is what ...
- 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. ...
- Hadoop:Task process exit with nonzero status of 1 异常
在运行hadoop程序时经常遇到异常 java.io.IOException: Task process exit with nonzero status of 1.网上很多博文都说是磁盘不够的问题. ...
- hadoop系列 第三坑: Task process exit with nonzero status of 137
跑MR的时候抛出异常: java.lang.Throwable: Child Error at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.j ...
- 2020年的UWP(2)——In Process App Service
最早的时候App Service被定义为一种后台服务,类似于极简版的Windows Service.App Service作为Background Task在宿主UWP APP中运行,向其他UWP A ...
- IIS启动失败,启动Windows Process Activation Service时,出现错误13:数据无效 ;HTTP 错误 401.2 - Unauthorized 由于身份验证头无效,您无权查看此页
因为修改过管理员账号的密码后重启服务器导致IIS无法启动,出现已下异常 1.解决:"启动Windows Process Activation Service时,出现错误13:数据无效&quo ...
- 二分+DP HDU 3433 A Task Process
HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- 为应用程序池“XX”提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误
场景 WCF应用程序部署在IIS7中,使用net.tcp协议对外给几百台客户端提供服务,应用程序池不断崩溃重启. 分析过程 在事件查看器中看到的错误信息类似于 为应用程序池“XX”提供服务的进程在与 ...
- hadoop出现namenode running as process 18472. Stop it first.
hadoop出现namenode running as process 18472. Stop it first.等等,类别似几个的出现. namenode running as process 32 ...
随机推荐
- zookeeper3.4.5集群安装
机器配置: 机器 Hostname user 192.168.169.139 node139 hadoop 192.168.169.140 node140 hadoop 192.168.169.141 ...
- 判断元素的16中方法expected_conditions
from selenium.webdriver.support import expected_conditons as EC 1.title_is:判断当前页面的title是否完全等于预期字符串,返 ...
- Java面向对象—继承
概述: 1.多个类相同的属性和功能抽取成另一个类, 让具有特有功能的类继承这个类. 2.通过 extends 关键字可以实现类与类的继承 格式: class 子类名 extends 父类名 {} 特点 ...
- dobbo 简单框架
- grid布局笔记
1.应用 display: grid 的元素.这是所有网格项(Grid Items)的直接父级元素.即容器 2.网格容器(Grid Container)的子元素(直接子元素). 3.注意:在 网格容器 ...
- System.Linq.Dynamic 动态查询
安装 VS->工具栏->NuGet程序管理器,System.Linq.Dynamic 注意: 使用动态查询必须先调用AsQueryable()方法,因为动态扩展仅适用于实现IQueryab ...
- HashMap与ConcurrentHashMap、HashTable
(1)HashMap的线程不安全原因一:死循环 原因在于HashMap在多线程情况下,执行resize()进行扩容时容易造成死循环. 扩容思路为它要创建一个大小为原来两倍的数组,保证新的容量仍为2的N ...
- 【WIN7】windows\system32 下的几乎所有文件的简单说明【1】
1: aclui.dll .....Security Descriptor Editor,没有它,注册表编缉器会无法运行 2: ACTIVEDS.DLL .....(ADs 路由层 DLL). 没有它 ...
- shell脚本小示例
求1-100自然数的和: 法一:for循环 #!/bin/bash # declare -i sum=0 for ((i=0;i<=100;i++));do let sum+=$i done e ...
- awk 连接字符串
awk中数据类型,是不需要定义,自适应的. 有时候需要强制转换.我们可以通过下面操作完成. 一.awk字符串转数字awk 'BEGIN{a="100";b="10test ...