android程序中查看系统内存使用情况
来个例子
private void displayBriefMemory() {
final ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(info);
Log.i(tag,"系统剩余内存:"+(info.availMem >> 10)+"k");
Log.i(tag,"系统是否处于低内存运行:"+info.lowMemory);
Log.i(tag,"当系统剩余内存低于"+info.threshold+"时就看成低内存运行");
}
三个指标:系统剩余内存,系统低内存门限,系统是否低内存运行标志
https://my.oschina.net/weiyanen/blog/90693
查看内存的可用空间 需要用到ActivityManager这个类,获取系统服务。
ActivityManager manager = (ActivityManager) getSystemService(context.ACTIVITY_SERVICE);
MemoryInfo info = new MemoryInfo();
manager.getMermoryInfo(info);
因为内存使用量的单位是byte,需要用long类型来接收
long memory = info.availMem;// 单位是byte,内存空间当前可用量
long totalMemory = info.totalMem//内存的总量,此获取总量的方式只有在API版本14以下使用会报错,但是clear Lint Markers 后也可以正常编译。
作者:流水线上的程序员
链接:https://www.jianshu.com/p/c56ec3d12b9e
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。