Can we rely on our Android app getting a set amount of memory or does it vary between phone models or OS versions?
For example, I have a memory cache, and I\'ve set
Yes, the maximum heap size varies from device to device. You can check the device's approximate per-application memory class by calling getMemoryClass().
Returns the approximate per-application memory class of the current device. This gives you an idea of how hard a memory limit you should impose on your application to let the overall system work best. The returned value is in megabytes; the baseline Android memory class is 16 (which happens to be the Java heap limit of those devices); some device with more memory may return 24 or even higher numbers.
The only built-in way to change heap size of an app is by setting android:largeHeap="true"
in the AndroidManifest.xml
. This will generally increase heap size from 48 to 128. Keep in mind this approach will only work on 3.x tablets. Otherwise, you'll need a rooted device, which is obviously not something you would want to rely on as a developer.