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 its limit to 5 MB. If on one device, my app will only get 8 MB of memory to play with, and on another, 24 MB, I’d like to tune the cap of the memory cache to take advantage of more or less memory.
Is there any way to figure this out, does the amount even vary?
Yes, the maximum heap size varies from device to device. You can check the device’s approximate per-application memory class by calling
getMemoryClass().The only built-in way to change heap size of an app is by setting
android:largeHeap="true"in theAndroidManifest.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.