android里,activity后台运行是可以被系统关闭的,当空间不够时,所以计算可用空间
包括两正在运行的除了service的所有进程。 这句理解了 ,才看的懂下面的公式。
经过查看android4.0系统的管理应用程序的源码,获得。
思路:
可用空间 = 闲置空间 + 缓存 + 所有后台非service进程
代码:
//通过读/proc/meminfo得到内存总大小
memInfoReader = new MemInfoReader();
memInfoReader.readMemInfo();
mAm = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
//
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
mAm. getMemoryInfo(memInfo);
long lFree = memInfoReader.getFreeSize() +
+ memInfoReader.getCachedSize()
+ memInfo.hiddenAppThreshold;
String free = Formatter.formatShortFileSize(getContext(), lFree);
String uesd = Formatter.formatShortFileSize(getContext(),memInfoReader.getTotalSize()-lFree);
包括两正在运行的除了service的所有进程。 这句理解了 ,才看的懂下面的公式。
经过查看android4.0系统的管理应用程序的源码,获得。
思路:
可用空间 = 闲置空间 + 缓存 + 所有后台非service进程
代码:
//通过读/proc/meminfo得到内存总大小
memInfoReader = new MemInfoReader();
memInfoReader.readMemInfo();
mAm = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
//
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
mAm. getMemoryInfo(memInfo);
long lFree = memInfoReader.getFreeSize() +
+ memInfoReader.getCachedSize()
+ memInfo.hiddenAppThreshold;
String free = Formatter.formatShortFileSize(getContext(), lFree);
String uesd = Formatter.formatShortFileSize(getContext(),memInfoReader.getTotalSize()-lFree);