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. Differences between Python2 and Python3

    @1:str, repr和反引号是Python将值转为字符串的3种方法repr创建一个字符串,它以合法的Python表达式的形式表示该字符串.Python2还有反引号`,但Python3中没有反引号, ...

  2. save a web page as a single file (mht format) using Delphi code

    Here's how to save a web page as a single file (mht format) using Delphi code: uses CDO_TLB, ADODB_T ...

  3. java栈的实现

    可以采用数组与链表两种方法来实现栈. 1.用数组实现栈 import java.util.Arrays; public class MyStack<E>{ private Object[] ...

  4. LeetCode:路径总和II【113】

    LeetCode:路径总和II[113] 题目描述 给定一个二叉树和一个目标和,找到所有从根节点到叶子节点路径总和等于给定目标和的路径. 说明: 叶子节点是指没有子节点的节点. 示例:给定如下二叉树, ...

  5. redis---在CentOS6.5下安装与配置

    本文详细介绍redis单机单实例安装与配置,服务及开机自启动.如有不对的地方,欢迎大家拍砖o(∩_∩)o (以下配置基于CentOS release 6.5 Final, redis版本3.0.2 [ ...

  6. SVN插件下载地址及更新地址

    SVN插件下载地址及更新地址,你根据需要选择你需要的版本.现在最新是1.8.xLinks for 1.8.x Release:Eclipse update site URL: http://subcl ...

  7. Oracle数据安全(四)j角色管理

    一.角色管理的概述 1.角色的概念 为了简化数据库权限的管理,在Oracle数据库中引入了角色的概念.所谓的角色就是一系列相关权限的集合. 2.角色的特点 在数据库中,角色的名称必须是唯一的,不能与用 ...

  8. Spark机器学习2·准备数据(pyspark)

    准备环境 anaconda nano ~/.zshrc export PATH=$PATH:/anaconda/bin source ~/.zshrc echo $HOME echo $PATH ip ...

  9. Zabbix 自定义Key

    系统:Linux Centos 7.4 x64.Windos 2008 x64 服务:Zabbix 3.0.16 说明1:自定义Key 主要通过自定义 脚本 或者 命令 来实现自定义监控类型,需要在a ...

  10. 【META http-equiv="Content-Type" Content="text/html; Charset=*】意义详解

    [META http-equiv="Content-Type" Content="text/html; Charset=*]意义详解 META,网页Html语言里Head ...