Skip to content

Instantly share code, notes, and snippets.

@mataanin
Last active December 19, 2015 03:39
Show Gist options
  • Save mataanin/5891668 to your computer and use it in GitHub Desktop.
Save mataanin/5891668 to your computer and use it in GitHub Desktop.
Android: Calculating memory cache size based on the memory available on the device
// Taken from Contacts List example
public static int calculateMemCacheSize(float percent) {
if (percent < 0.05f || percent > 0.8f) {
throw new IllegalArgumentException("setMemCacheSizePercent - percent must be "
+ "between 0.05 and 0.8 (inclusive)");
}
return Math.round(percent * Runtime.getRuntime().maxMemory() / 1024);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment