如何检测Lowmemory android系统中? [英] How to Detect Lowmemory in android?

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

问题描述

我的应用程序有大量的图片,有时崩溃内存不足。 我写了这个功能,我发现在开发者网站。
公共无效onLowMemory(){

My application has a lot of images and sometimes it crashes due to low memory. I wrote this function that I found on the developer site.
public void onLowMemory(){

}

但问题是,这个功能永远不会在那些低内存的情况下调用。 我应该怎么做,使这个函数被调用。 我需要提醒用户的时候有自己的设备上内存不足。

But the problem is that this function never gets called during those low memory circumstances. What should I do to make this function to be called. I need to alert users when there is low memory on their device.

推荐答案

onLowMemory()是不是一个很大的帮助,因为它只有被称为有时那里的整个系统运行内存和的不是的的情况下的的应用程序正在运行出其可用的堆空间。

onLowMemory() is not a big help because it gets called only at times where the overall system is running out of memory and not in cases where your app is running out of its available heap space.

所以我的答案是,你不应该依赖于 onLowMemory()被调用。恕我直言,没有你的问题回调方法。

So my answer is that you should not depend on onLowMemory() being invoked. And IMHO there is no callback method for your problem.

您只需定期轮询可用的堆空间,并检查是否正在运行内存不足或没有。

You can simply poll periodically the available heap space and check whether you are running out of memory or not.

Runtime.getRuntime().maxMemory();
Runtime.getRuntime().totalMemory();
Runtime.getRuntime().freeMemory();

这篇关于如何检测Lowmemory android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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