1.ADB命令获取
命令:adb shell dumpsys meminfo packName(你的包名)

2.代码获取APP 占用的内存信息
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int pid = android.os.Process.myPid();
Log.i("Test_Log", "pid=" + pid);
Debug.MemoryInfo memoryInfo = activityManager.getProcessMemoryInfo(new int[]{pid})[0];
int totalPss = memoryInfo.getTotalPss();
int dalvikPss = memoryInfo.dalvikPss;
int nativePss = memoryInfo.nativePss;
int otherPss = memoryInfo.otherPss;
Log.i("Test_Log","总内存: " + String.format("%4.2f", totalPss/1024.0f) + " MB \n"
+ "dalvikPss:" + String.format("%4.2f", dalvikPss/1024.0f) + " MB \n"
+ "nativePss:" + String.format("%4.2f", nativePss/1024.0f) + " MB \n"
+ "otherPss:" + String.format("%4.2f", otherPss/1024.0f) + " MB \n");
3.Android Studio的Profiler工具
这个无需多说



594

被折叠的 条评论
为什么被折叠?



