轉(zhuǎn)載至:https://juejin.cn/post/7098257692828893220
Java代碼獲取內(nèi)存信息:
private void getMaxMemoryInfo() {
Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.e("XMemory", "Dalvik MaxMemory:" + Long.toString(maxMemory / (1024 * 1024)));
ActivityManager activityManager = (ActivityManager) ContextHolder.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
Log.e("XMemory", "Dalvik MemoryClass:" + Long.toString(activityManager.getMemoryClass()));
Log.e("XMemory", "Dalvik LargeMemoryClass:" + Long.toString(activityManager.getLargeMemoryClass()));
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
Log.e("XMemory", "系統(tǒng)總內(nèi)存:" + (info.totalMem / (1024 * 1024)) + "M");
Log.e("XMemory", "系統(tǒng)剩余內(nèi)存:" + (info.availMem / (1024 * 1024)) + "M");
Log.e("XMemory", "系統(tǒng)是否處于低內(nèi)存運(yùn)行:" + info.lowMemory);
Log.e("XMemory", "系統(tǒng)剩余內(nèi)存低于" + (info.threshold / (1024 * 1024)) + "M時(shí)為低內(nèi)存運(yùn)行");
}