zoukankan      html  css  js  c++  java
  • [转]Android系统的进程,任务,服务的信息

    本文转自:http://www.cnblogs.com/yangxiao24/archive/2011/07/03/2096662.html

       获取android系统中进程,任务,服务信息,需要通过ActivityManager类来实现。

            ActivityManager的功能是为系统中所有运行着的Activity交互提供了接口。       

            ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); 

            通过 List<RunningTaskInfo> runningTasks = am.getRunningTasks(maxNum);返回任务列表信息

            通过List<RunningServiceInfo> serivces = am.getRunningServices(maxNum);返回服务列表信息

            通过List<RunningAppProcessInfo> apps = am.getRunningAppProcesses(); 返回进程列表信息

    下面是RunningTaskInfo,RunningServiceInfo,RunningAppProcessInfo,三个类的解释:

    Android.app.ActivityManager.RunningTaskInfo

    属性名称

    数据类型

    描述

    baseActivity

    ComponentName

    任务做为第一个运行中的Activity组件信息

    description

    CharSequence

    任务当前状态的描述

    id

    Int

    任务的ID

    numActivities

    Int

    任务中所运行的Activity数量,包含已停止的

    numRunning

    Int

    任务中所运行的Activity数量,不包含已停止或不延续运行的

    thumbnall

    Bitmap

    任务当前状态的位图表示,目前为null

    topActivity

    ComponentName

    处于任务栈的栈顶的活动组件

    Android.app.ActivityManager.RunningServiceInfo

    属性名称

    数据类型

    描述

    activeSince

    long

    服务第一次被激活的时间 (启动和绑定方式)

    clientCount

    Int

    接到该服务的客户端数目

    crashCount

    Int

    服务运行期间,出现死机的次数

    foreground

    Boolean

    若为true,则该服务在后台执行

    lastActivityTime

    Long

    最后一个Activity与服务绑定的时间

    pid

    int

    若此值不为0,则表示正在运行服务的Id

    Process

    String

    该服务的名称

    restarting

    long

    若此值不为0,则表示该服务不在运行中,将在参数给定的时间点重启服务

    service

    ComponentName

    服务的组件名称

    started

    boolean

    若此值为true,则表示服务已经在启动运行中


    Android.app.ActivityManager.RunningAppProcessInfo

    属性名称

    数据类型

    描述

    importance

    int

    进程在系统中的重要级别

    importanceReasonCode

    int

    进程的重要原因代码

    importanceReasonComponent

    ComponentName

    进程中组件的描述信息

    importanceReasonPid

    int

    当前进程的子进程Id

    lru

    int

    在同一个重要级别内的附加排序值

    pid

    int

    当前进程Id

    pkgList

    String[]

    被载入当前进程的所有包名

    processName

    String

    当前进程的名称

    uid

    int

    当前进程的用户Id

    代码:

                获取任务信息

                @Override
                public void onClick(View v) {
                    
                    String info = "";
                    List<RunningTaskInfo> runningTasks = am.getRunningTasks(maxNum);
                    for (RunningTaskInfo task:runningTasks){
                        info += "一个任务信息开始:\n";  
                        info += "启动当前任务的activity名称:" + task.baseActivity.getClassName()+ "\n";
                        info += "当前任务状态的描述:" + task.description.toString()+ "\n";
                        info += "当前任务Id:" + task.id+ "\n";
                        info += "任务中所运行的Activity数量,包含已停止的:" + task.numActivities+ "\n";
                        info += "任务中所运行的Activity数量,不包含已停止或不延续运行的:" + task.numRunning+ "\n";  

                        System.out.print(info);
     

                    }
                }

     

                服务获取信息

               @Override
                public void onClick(View v) {
                    
                    String info = "";
                    List<RunningServiceInfo> serivces = am.getRunningServices(maxNum);  
                    for (RunningServiceInfo service:serivces){
                        info = "一个service信息开始:\n";  
                        info += "服务第一次被激活的时间:" + service.activeSince + "\n";  
                        info += "接到该服务的客户端数目:" + service.clientCount+ "\n";
                        info += "服务运行期间,出现死机的次数:" + service.crashCount+ "\n";
                        info += "若为true,则该服务在后台执行:" + service.foreground+ "\n";
                        info += "最后一个Activity与服务绑定的时间:" + service.lastActivityTime+ "\n";
                        info += "正在运行服务的Id:" + service.pid+ "\n";
                        info += "该服务的名称:" + service.process+ "\n";
                        info += "服务的组件名称:" + service.service+ "\n";
                        info += "若此值为true,则表示服务已经在启动运行中:" + service.started+ "\n";
                        info += "若此值不为0,则表示该服务不在运行中,将在参数给定的时间点重启服务:" + service.restarting+ "\n";
                        
                        System.out.print(info);

                    }
                }

     

                进程获取信息
                @Override
                public void onClick(View v) {
                    
                    String info = "";
                    List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
                    for(RunningAppProcessInfo app:apps){
                        info = "进程信息开始:\n";
                        info += "当前进程的用户Id:" + app.uid + "\n";
                        info += "当前进程的名称:" + app.processName + "\n";
                        info += "当前进程Id:" + app.pid + "\n";
                        info += "进程在系统中的重要级别:" + app.importance + "\n";
                        info += "进程的重要原因代码:" + app.importanceReasonCode + "\n";
                        info += "进程中组件的描述信息:" + app.importanceReasonComponent + "\n";
                        info += "当前进程的子进程Id:" + app.importanceReasonPid + "\n";
                        info += "在同一个重要级别内的附加排序值:" + app.lru + "\n";
                        
                        System.out.print(info);
                    }
                }

     
  • 相关阅读:
    Calling a parent window function from an iframe
    JSON with Java
    Posting array of JSON objects to MVC3 action method via jQuery ajax
    What's the difference between jquery.js and jquery.min.js?
    jquery loop on Json data using $.each
    jquery ui tabs详解(中文)
    DataTables warning requested unknown parameter
    Datatables 1.10.x在命名上与1.9.x
    jQuery 1.x and 2.x , which is better?
    DataTabless Add rows
  • 原文地址:https://www.cnblogs.com/freeliver54/p/2231458.html
Copyright © 2011-2022 走看看