码迷,mamicode.com
首页 > 移动开发 > 详细

23、获取app所占据的内存

时间:2015-03-14 12:25:00      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

 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     }

 

23、获取app所占据的内存

标签:

原文地址:http://www.cnblogs.com/kunyashaw/p/4337261.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!