美文网首页Android Other
Android中获取内存信息

Android中获取内存信息

作者: 强大帅 | 来源:发表于2022-10-10 17:32 被阅读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时为低内存运行");
}

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

相关文章

网友评论

    本文标题:Android中获取内存信息

    本文链接:https://www.haomeiwen.com/subject/tuflgrtx.html