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. struts2基础——需要注意的几点

    struts是流行和成熟的基于MVC设计模式的web应用程序框架,使用struts可以帮助我们减少运用MVC设计模型来开发web应用的时间. 目录: 一.struts2的工作原理及文件结构 二.三种访 ...

  2. UVALive 6911 F - Double Swords

    思路:1.把所有有长度的剑看做点.Ai点是肯定要取.然后求另一把剑. 先对右区间排个序,然后每次看这个区间范围内有没有剑,如果没有就添加一把(值为右端点的剑): 如果有并且数量为1且这条龙的Ai等这把 ...

  3. unity,如何手动或者使用代码更换材质

    在unity中,我们可能需要更换怪物的贴图,来达到以下效果 方法1:手动配置 找到自己配置好的扩展名为.mat的文件,在怪物的节点找到带Mesh Render的子元素,将其拖放到如图位置 方法2:代码 ...

  4. 使用curl 命令模拟POST/GET请求

    https://blog.csdn.net/u012340794/article/details/71440604 curl命令是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载 ...

  5. 【c++ primer, 5e】类的其他特性(卒)

    1 - Class Members Revisited 2 - Functions That Return *this 3 - Class Types 4 - Friendship Revisited ...

  6. windows 安装python3.5启动报错:api-ms-win-crt-runtime-l1-1-0.dll丢失

    下载: api-ms-win-crt-runtime就是MFC的运行时环境的库,python在windows上编译也是用微软的visual studio C++编译的,底层也会用到微软提供的C++库和 ...

  7. Spring积累

    <tx:annotation-driven/>  (Spring的XML配置里两大Bean的声明之一) 那我们是否就可以在程序中所有被spring管理的类(@Controller.@Ser ...

  8. Newtonsoft.Json 序列 反序列 IEnumerable

    下面是memcached 中获取的obj 类型的数据,转list string sessionId = Request.Cookies["sessionId"].Value;//授 ...

  9. LeetCode第[14]题(Java): Longest Common Prefix

    题目:最长公共前缀 难度:EASY 题目内容: Write a function to find the longest common prefix string amongst an array o ...

  10. Webstorm常用快捷键备忘(Webstorm入门指南)

    WebStorm 是jetbrains公司旗下一款JavaScript 开发工具.被广大中国JS开发者誉为“Web前端开发神器”.“最强大的HTML5编辑器”.“最智能的JavaSscript IDE ...