Memory manegment problem with downloaded images on android
<p>I’m having a little problem with an app I’m working on. The app shows a gallery that shows between 1 and 70+ pictures (one at a time), all downloaded from the web.</p>

<p>At first I save a low resolution picture and after I finish downloading all low res pictures, I start downloading the high resolution ones and replacing them.</p>

<p>The problem comes when I start downloading the high dpi ones. After some are downloaded I get a memoryOutOfBoundsException (which can be expected).</p>

<hr>

<p>To solve that kind of problem in android I’ve seen four options:</p>

<p><strong>1.- Using androids Cache Manager.</strong></p>

<p>This is limited to Web Views (So I can’t use them).</p>

<p><strong>2.- Loading the hi res picture every time the user passes thru a picture.</strong></p>

<p>That will make the bad resolution picture appear every time the user changes the picture until the high resolution one (which is loading on the background) gets downloaded and switched. Making the application look bad.</p>

<p><strong>3.- Creating some kind of RAM cache that can hold like 5 pictures and use something like the second method.</strong></p>

<p>In this case, I’ll try to have, in the ram, the 5 hi res pictures nearest to the one that is being showed  (either downloaded or being downloaded) so that the app can show hi res pictures for the ones that are near the selected one without having to download them after the user gets to see the low res picture.</p>

<p><strong>4.- Creating a personal Cache Manager</strong></p>

<p>In this case I’ll create a personal cache manager that saves the pictures on the SD card and uses those pictures on the gallery. This also brings one problem, I’ll depend on the user having an SD card on the device. For solving the problem of the files staying on the device after the app is deleted (If the app gets deleted), I’ll just delete all the files on the onDestroy() method of the app (I don’t mind loading them again).</p>

<hr>

<p>In my opinion, the best option is the fourth. Method, which forces me to depend on the user having an SD card.</p>

<p>Now my questions.</p>

<p>Is there any other way of solving my problem?</p>

<p>Is there another kind of memory on the device than can be used to evade the dependency of the SD card?. Following the question. Is it recommended to use that kind of memory or does using it bring other problems?. (Also, a tutorial about it wold be apreciated.)</p>

<p>Do users usually have SD cards or is the fourth option the worst one?</p>

<p>Thank you in advance.</p>
