Android Other

Android中获取内存信息

2022-10-10  本文已影响0人  强大帅

转载至:https://juejin.cn/post/7098257692828893220

Java代码获取内存信息:

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", "系统总内存:" + (info.totalMem / (1024 * 1024)) + "M");
   Log.e("XMemory", "系统剩余内存:" + (info.availMem / (1024 * 1024)) + "M");
   Log.e("XMemory", "系统是否处于低内存运行:" + info.lowMemory);
   Log.e("XMemory", "系统剩余内存低于" + (info.threshold / (1024 * 1024)) + "M时为低内存运行");
}

通过名命令行获取内存信息:

上一篇下一篇

猜你喜欢

热点阅读