diff options
| author | 2013-01-14 06:15:20 -0800 | |
|---|---|---|
| committer | 2013-01-14 06:15:20 -0800 | |
| commit | 1a551b1614a1717fab7955bb712f8f8b35e22be9 (patch) | |
| tree | ba924ed88727c43723633ca92a3260bf5dae5bc3 | |
| parent | 5327322ab94711a654d41a5b53be3bf6a3a28a39 (diff) | |
| parent | 6f680f524a66dabcf0d86d0f19f3855f8c5e594f (diff) | |
am 6f680f52: Displaying Bitmaps Efficiently Training - Change memory calculation
* commit '6f680f524a66dabcf0d86d0f19f3855f8c5e594f':
Displaying Bitmaps Efficiently Training - Change memory calculation
| -rw-r--r-- | docs/downloads/training/BitmapFun.zip | bin | 430475 -> 430504 bytes | |||
| -rw-r--r-- | docs/html/training/displaying-bitmaps/cache-bitmap.jd | 15 |
2 files changed, 8 insertions, 7 deletions
diff --git a/docs/downloads/training/BitmapFun.zip b/docs/downloads/training/BitmapFun.zip Binary files differindex c4ea7aa92c4b..882ce03c4eb6 100644 --- a/docs/downloads/training/BitmapFun.zip +++ b/docs/downloads/training/BitmapFun.zip diff --git a/docs/html/training/displaying-bitmaps/cache-bitmap.jd b/docs/html/training/displaying-bitmaps/cache-bitmap.jd index 2a333ccae62f..417ec5bb60b2 100644 --- a/docs/html/training/displaying-bitmaps/cache-bitmap.jd +++ b/docs/html/training/displaying-bitmaps/cache-bitmap.jd @@ -101,19 +101,20 @@ private LruCache<String, Bitmap> mMemoryCache; @Override protected void onCreate(Bundle savedInstanceState) { ... - // Get memory class of this device, exceeding this amount will throw an - // OutOfMemory exception. - final int memClass = ((ActivityManager) context.getSystemService( - Context.ACTIVITY_SERVICE)).getMemoryClass(); + // Get max available VM memory, exceeding this amount will throw an + // OutOfMemory exception. Stored in kilobytes as LruCache takes an + // int in its constructor. + final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. - final int cacheSize = 1024 * 1024 * memClass / 8; + final int cacheSize = maxMemory / 8; mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { - // The cache size will be measured in bytes rather than number of items. - return bitmap.getByteCount(); + // The cache size will be measured in kilobytes rather than + // number of items. + return bitmap.getByteCount() / 1024; } }; ... |