Android获取当前可用内存

幼敏悟过人,读书辄成诵。这篇文章主要讲述Android获取当前可用内存相关的知识,希望能为你提供帮助。

写入本地文件
private void getMemo(){ //获得ActivityManager服务的对象 ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); //获得MemoryInfo对象 ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo() ; //获得系统可用内存,保存在MemoryInfo对象上 mActivityManager.getMemoryInfo(memoryInfo) ; long memSize = memoryInfo.availMem ; selfHttpRequest.writeToLoacl(memSize+" " ); Toast.makeText(this, " success" , Toast.LENGTH_SHORT).show(); }

【Android获取当前可用内存】Toast形式
private void toastMemo(){ //获得ActivityManager服务的对象 ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); //获得MemoryInfo对象 ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo() ; //获得系统可用内存,保存在MemoryInfo对象上 mActivityManager.getMemoryInfo(memoryInfo) ; long memSize = memoryInfo.availMem ; double mem = memSize / (1000*1000); Toast.makeText(this, mem+" MB " , Toast.LENGTH_SHORT).show(); }


    推荐阅读