Question

Is there a good way to check how much memory out of overall heap size has the device in Java? My app, which is written in adobe air, uses native Java extension to load multiple images from SD Card. I found this piece of code to check if bitmap could be loaded into memory:

public boolean checkBitmapFitsInMemory(long bmpwidth,long bmpheight, int bmpdensity ){

        long reqsize=bmpwidth*bmpheight*bmpdensity;
        long allocNativeHeap = Debug.getNativeHeapAllocatedSize();
        final long heapPad=(long)Math.max(4*1024*1024,Runtime.getRuntime().maxMemory()*0.1);
        if ((reqsize + allocNativeHeap + heapPad) >= Runtime.getRuntime().maxMemory())
        {
            return false;
        }
        return true;

    }

However, it seems that on my Galaxy S2 it is completely ignored. Maybe because the app consists of two parts - one is Java second is adobe air. Is there another memory values i should check before loading image into applications memory? Thank you!

Was it helpful?

Solution

Check out Android Runtime

Calling Runtime.getRuntime().freeMemory() returns memory resources available to the running application.

Also, this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top