23、获取app所占据的内存

 1 public static  void getRunningAppProcessInfo(ActivityManager mActivityManager) { 
 2         //ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 
 3        
 4         if(mActivityManager != null)
 5         {
 6             //获得系统里正在运行的所有进程 
 7             List<RunningAppProcessInfo> runningAppProcessesList = mActivityManager.getRunningAppProcesses(); 
 8            
 9             for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcessesList) { 
10                 // 进程ID号 
11                 int pid = runningAppProcessInfo.pid; 
12                 // 用户ID 
13                 int uid = runningAppProcessInfo.uid; 
14                 // 进程名 
15                 String processName = runningAppProcessInfo.processName; 
16                 // 占用的内存 
17                 int[] pids = new int[] {pid}; 
18                 Debug.MemoryInfo[] memoryInfo = mActivityManager.getProcessMemoryInfo(pids); 
19                 int memorySize = memoryInfo[0].dalvikPrivateDirty; 
20                 if(processName.equals("com.huofu"))
21                 {
22                         CommonUtils.LogWuwei(tag,"processName="+processName+",pid="+pid+"\nuid="+uid+"\nmemorySize="+memorySize/1024+"M");
23                         break;
24                 }
25                  
26             } 
27         }
28         else
29         {
30             CommonUtils.LogWuwei(tag, "mActivityManager is null");
31         }
32         
33     }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。