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 ...
随机推荐
- go——变量
在数学概念中,变量(variable)表示没有固定值且可以改变的数.但从计算机系统实现角度来看,变量是一段或多段用来存储数据的内存.作为静态类型语言,Go语言总是有固定的数据类型,类型决定了变量内存的 ...
- 面向对象封装 classmethod和staticmethod方法
接口类 接口类:是规范子类的一个模板,只要接口类中定义的,就应该在子类中实现接口类不能被实例化,它只能被继承支持多继承接口隔离原则:使用多个专门的接口,而不使用单一的总接口.即客户端不应该依赖那些不需 ...
- oracle中记录被另一个用户锁住的原因与解决办法
oracle数据中删除数据时提示“记录被另一个用户锁住” 解决方法: 1.查看数据库锁,诊断锁的来源及类型: select object_id,session_id,locked_mode from ...
- IOS UIApplicationMain函数
对于UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString ...
- URAL 2081 Faulty dial
题目: Faulty dial Pavel has not played ACM for ages, nor does he train teams, nor prepare problems. Th ...
- udev和mdev hotplug事件
关于udev和mdev之间的区别与联系我发现自己现在还没有把它完整的给区分开来和联系起来. 设备文件系统有devfs,mdev,udev mdev是udev的简化版本,是busybox中所带的程序,最 ...
- C# 字符串中正则表达式的应用
1.截取字符串中指定内容 {"weatherinfo":{"city":"北京","cityid":"1010 ...
- win7 64位下使用regsvr32注册activex dll .
由于公司产品用了很多activex dll,而我的操作系统是64位的win7,在注册这些dll时碰到了很多问题,经过摸索,最后还是成功注册了,步骤如下: 1.在C:\Windows\SysWOW64\ ...
- 【Java】仿真qq尝试:用户注册(三)
需求: 实现用户名和密码存入数据库. 思路: 1.连接数据表用静态加载块 2.crud写成4个静态方法 具体流程: from:https://www.tutorialspoint.com/jdbc/j ...
- idea setting
input