Obtains information about all processes running by the system.

Source: Internet
Author: User

Obtains information about all processes running by the system.

Some tool classes written by myself

 

Public class TaskInfoUtils {/*** obtain information about all processes ** @ param pContext * @ return */public static List <TaskInfo> getTaskInfos (Context pContext) {// 1 obtain ActivityManager and PackageManager ActivityManager _ ActivityManager = (ActivityManager) pContext. getSystemService (pContext. ACTIVITY_SERVICE); PackageManager _ PackageManager = pContext. getPackageManager (); List <TaskInfo> _ TaskInfos = new ArrayList <TaskInfo> (); // 2 get the List of all processes running <RunningAppProcessInfo> _ RunningAppProcessInfos = _ ActivityManager. getRunningAppProcesses (); // 3 traverses the process and obtains its information for (Response handler: _ RunningAppProcessInfos) {TaskInfo _ TaskInfo = new TaskInfo (); MemoryInfo [] memoryInfos = _ ActivityManager. getProcessMemoryInfo (new int [] {runningAppProcessInfo. pid}); long _ MemSize = memoryInfos [0]. getTotalPrivateDirty () * 1024; // The memory consumed by the process String _ packageName = runningAppProcessInfo. processName; // process package ApplicationInfo _ ApplicationInfo; try {_ ApplicationInfo = _ PackageManager. getApplicationInfo (_ packageName, 0); Drawable _ Icon = _ ApplicationInfo. loadIcon (_ PackageManager); // program icon String _ Name = _ ApplicationInfo. loadLabel (_ PackageManager ). toString (); // program name_taskinfo. setIcon (_ Icon); _ TaskInfo. setMemsize (_ MemSize); _ TaskInfo. setName (_ Name); _ TaskInfo. setPackname (_ packageName); if (_ ApplicationInfo. flags & ApplicationInfo. FLAG_SYSTEM) = 0) {// user process _ TaskInfo. setUserTask (true);} else {// system process _ TaskInfo. setUserTask (false);} _ TaskInfos. add (_ TaskInfo);} catch (NameNotFoundException e) {// TODO Auto-generated catch block e. printStackTrace () ;}} return _ TaskInfos;} class TaskInfo {private Drawable icon; private String name; private long memsize; private boolean userTask; private String packname; public Drawable getIcon () {return icon;} public void setIcon (Drawable icon) {this. icon = icon;} public String getName () {return name;} public void setName (String name) {this. name = name;} public long getMemsize () {return memsize;} public void setMemsize (long memsize) {this. memsize = memsize;} public boolean isUserTask () {return userTask;} public void setUserTask (boolean userTask) {this. userTask = userTask;} public String getPackname () {return packname;} public void setPackname (String packname) {this. packname = packname ;}@ Override public String toString () {return "TaskInfo [name =" + name + ", memsize =" + memsize + ", userTask = "+ userTask +", packname = "+ packname +"] ";}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.