How to Detect Lowmemory in android?

前端 未结 7 1667
-上瘾入骨i
-上瘾入骨i 2021-02-13 14:34

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 onLowM         


        
7条回答
  •  孤独总比滥情好
    2021-02-13 15:20

    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.

    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 the available heap space and check whether you are running out of memory or not.

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

提交回复
热议问题