因為需求說盡量滿足最大像素圖片的渲染,但加載大圖需要更多 memory,所以我肯定需要做一個判斷,防止 oom,網上沖浪了下,發現通過下面幾個代碼可以拿到 app 的最大可用記憶體
public static float getMaxMemory() {
return Runtime.getRuntime().maxMemory() / 1024f / 1024f;
} public static ActivityManager.MemoryInfo getMemoryInfo(Context context) {
if (context == null) {
return null;
}
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
return mi;
}val manager=(this.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager)
val heapGrowthLimit= manager.memoryClass
經測驗發現,上述回傳的最大可用記憶體是512m,但是,我在 Android Studio 里面通過查看 profiler 的 memory 模塊,可以看到我的 app 最大已經超過 1g 的 memory

明顯和 512m 不符啊,那到底怎么能拿到最大的記憶體數呢?
uj5u.com熱心網友回復:
手機運存是 8g 的轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/85813.html
標籤:Android
上一篇:一個關于auto.js的問題
下一篇:大家有沒有在亞馬遜里發布過app
