如何获得当前内存使用android系统中? [英] How to get current memory usage in android?

查看:114
本文介绍了如何获得当前内存使用android系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用的/ proc / meminfo中并解析命令response.however其结果表明:

I have used /proc/meminfo and parsed command response.however it result shows that :

MemTotal:94348 KB MemFree:5784 KB

MemTotal: 94348 kB MemFree: 5784 kB

表示。它表明,只有5MB可用内存。是否有可能与Android手机? 只有5-6安装在我的手机应用程序,并没有其他任务运行。但还是这个命令显示有很少的可用内存。

means. it shows there is only 5MB free memory. Is it possible with android mobile? There is only 5-6 application installed on my mobile and no other task is running. but still this command shows there is very little free memory.

有人可以澄清这一点?或者是有越来越内存使用android系统中的任何其他方式?

Can somebody clarify this? or is there any other way of getting memory usage in android?

推荐答案

感谢您。它的完成和它的作品!

Thank you. Its done and it works !

让我来告诉你我做什么,所以其他人谁访问这个线程可以谙步骤:

Let me tell you what I did, So others who visit this thread can come to know the steps:

  1. 解析的/ proc / meminfo中的命令。您可以参考code在这里:<一href="http://stackoverflow.com/questions/3118234/how-to-get-memory-usage-and-cpu-usage-in-android">Get在Android的内存使用

使用跌破code和获取当前RAM:

use below code and get current RAM:

MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L;

//Percentage can be calculated for API 16+
long percentAvail = mi.availMem / mi.totalMem;

说明1048576

1024 bytes      == 1 kilobyte  
1024 kilobytes  == 1 megabyte  

1024 * 1024     == 1048576

这是相当明显,一些用来从字节转换为兆

It's quite obvious that the number is used to convert from bytes to megabytes

PS:我们需要计算一次总内存。所以在你的code调用一次1点,然后以后,你可以调用2点重复的code。

P.S: we need to calculate total memory only once. so call point 1 only once in your code and then after, you can call code of point 2 repetitively.

这篇关于如何获得当前内存使用android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆