Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>since it's usually impractical to load all bitmaps into memory for Android, you should assume that you will get GC from time to time.</p> <p>however, what you can do it consider the next tips:</p> <ol> <li><p>downscale the bitmaps to the sizes you need to show them. you can use <a href="http://developer.android.com/training/displaying-bitmaps/index.html" rel="nofollow noreferrer"><strong>google's way</strong></a> or <a href="https://stackoverflow.com/a/17773344/878126"><strong>my way</strong></a>.</p></li> <li><p>check in which folder you've put the image files. many people put them in the res/drawable folder and don't understand why they get to be so much larger than their original sizes (it's because of the density - it's mdpi while the device is probably xhdpi or xxhdpi). </p> <p>for example, if an image is in the drawable folder and you run it on an xhdpi device (like the galaxy S3), it would take (WIDTH*2)*(HEIGHT*2)*4 bytes . if the image is 200x200 , its bitmap object would take at least 400*400*4=640,000 bytes . it would be even worse on an xxhdpi device , like the galaxy s4 and htc one . </p></li> <li><p>consider using a memory cache, like the <a href="http://developer.android.com/reference/android/util/LruCache.html" rel="nofollow noreferrer"><strong>LruCache</strong></a></p></li> <li><p>if the bitmaps do not have transparency, and you don't see any difference in quality, consider using the <a href="http://developer.android.com/reference/android/graphics/Bitmap.Config.html" rel="nofollow noreferrer"><strong>RGB_565 config</strong></a> instead of default one. this will take 2 bytes per pixel instead of 4 bytes per pixel.</p></li> <li><p>if you can be responsible enough, you can use JNI for the caching. i've made a small code for this task, <a href="https://stackoverflow.com/questions/18250951/jni-bitmap-operations-for-helping-to-avoid-oom"><strong>here</strong></a> . please read all of the notes i've written there.</p></li> </ol> <p>btw, i've noticed you used an array of identifiers for the images. if the images have some logic in their names (example : img1,img2,...), you could use getResources().getIdentifier(...) instead. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload