Pergunta

I have an app where I am downloading a lot of small images and saving them to the SD Card. The files are mostly small (around 100kb), and are being saved to the SD Card. The problem is that I am having a lot of OutOfMemory errors even thought I have set largeHeap to true. I tried using Threads to do this and it appears to not be saving all the files I have, it skips about 10% of the files (30 out of 350 files are not saved). What is the best way to solve this problem? I am open to using JNI for it as well.

Foi útil?

Solução

One thing you can try is using Bitmap.Recycle() after you finished with your bitmap to help the GC clean the object if you are not doing that already. Most likely this will help but not solve the problem.

The other thing is if you are using threads (AsyncTask would be a better option), are you managing the number of concurrent threads? For example, set a MAX number of downloads and don't start a new download until the number of concurrent downloads is less than MAX.

There is a nice way of downloading pics for a listview here, it may bring you some ideas. http://developer.android.com/training/displaying-bitmaps/process-bitmap.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top