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);
        }
    }
}
时间: 2024-11-09 05:59:11

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

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. For whatever reason, last week both of my Vista 64-bit machines suddenly stopped being able to start IIS (Internet Information Server). The service j

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

跑MR的时候抛出异常: java.lang.Throwable: Child Error at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.java:250) Caused by: java.io.IOException: Task process exit with nonzero status of 137. at org.apache.hadoop.mapred.TaskRunner.run(TaskRunner.java:237)

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

在运行hadoop程序时经常遇到异常 java.io.IOException: Task process exit with nonzero status of 1.网上很多博文都说是磁盘不够的问题. 其实我很多时候遇到这个问题是因为程序抛出org.apache.hadoop.mapred.Child: Error running child : java.lang.OutOfMemoryError:   unable to create new native thread这个问题导致程序失败并

Linux中的task,process, thread 简介

本文的主要目的是介绍在Linux内核中,task,process, thread这3个名字之间的区别和联系.并且和WINDOWS中的相应观念进行比较.如果你已经很清楚了,那么就不用往下看了. LINUX版本:2.6.18ARCH: X86 首先要明确的是,按照LKD 2里面的说法,LINUX和其他OS 比如WINDOWS, SOLARIS之间一个很大的不同是没有严格定义的线程(thread).那么你也许会问,如果LINUX中没有线程,那么如何来表示类似WINDOWS 线程的那种执行观念呢?答案是

二分+DP HDU 3433 A Task Process

HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1368    Accepted Submission(s): 684 Problem Description There are two kinds of tasks, namely A and B. There are N workers

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

hadoop出现namenode running as process 18472. Stop it first.等等,类似的出现了好几个. namenode running as process 32972. Stop it first. 127.0.0.1: ssh: connect to host 127.0.0.1 port 22: No error 127.0.0.1: ssh: connect to host 127.0.0.1 port 22: No error jobtracke

IIS 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误的解决方法

系统环境:Windows Server 2008 R2 64位, IIS 7.0 错误信息: 为应用程序池提供服务的进程在与 Windows Process Activation Service 通信时出现严重错误.该进程ID为. 应用程序池将被自动禁用,原因是为此应用程序池提供服务的进程中出现一系列错误. 导致网站不能访问,出现 503 错误,服务不可用,Service Unavailable. 解决的方法: 1. 将应用程序池设置为 经典 Classic 模式(如果是纯.NET应用,此步骤可

在启动Windows Process Activation Service时,出现错误13:数据无效

在启动Windows Process Activation Service时,出现错误13:数据无效 1.错误原因: 当Windows Process Activation Service从C:\Windows\system32\inetsrv\config\applicationHost.config中读取configuration数据时,数据收到了损坏,错误消息是:Configuration file is not well-formed XML,数据无效. 2.解决方法: 将c:\inet

启动zookeeper报错already running as process

今天启动zookeeper的时候报错: [[email protected] zookeeper-3.4.5]# bin/zkServer.sh startJMX enabled by defaultUsing config: /root/zookeeper/zookeeper-3.4.5/bin/../conf/zoo.cfgStarting zookeeper ... already running as process 947.. 看了下947这个进程,发现是linux系统进程,应该不会冲