When to process a bitmap in an android project?

I have successfully implemented lazy loading from a list of images and list items in an Android list. I am using Android 4.0 and Java 7.

The following algorithm is:

  • List data (including image URLs) is downloaded from the Internet as the user scrolls through the list.

  • When the scroll state is idle, list images are loaded.

  • In the background stream, the images are first checked in the cache. If they are not present in the cache, they are loaded and stored in the cache.

  • Ultimately, the image is set to view images in the list, and the adapter is notified.

The only problem is I don’t understand when to process bitmap images. I tried using bitmap.recyle () in many places, but got the following error:

java.lang.IllegalArgumentException: Unable to draw recycled raster map

It is not possible to add this extensive code here. There are also some privacy issues. Can someone please help me about this?

EDIT

The size of my application is increasing from 727 KB (at the time of installation) to 14 MB. After I reworked my bitmaps, in the getView () of the adapter, I get " cannot generate texture from the bitmap . " Can anyone suggest how to get rid of it?

+4
source share
3 answers

Recycling a bitmap makes it unusable. Only recycle when you fully cope with it. In your case, this means that after it is evicted from the cache. You will also want to make sure that none of your existing views refers to it.

+2
source

In connection with ICS, there is no need for processing. There are a few examples where you would like to, but given most of the implementations of listview, you probably won't need this.

You can check out this video from Chet Hasse for more information on reusing bitmaps that would be better if they were the same size. DevBytes: Raster Image Distribution

0
source

Bitmap disposal should be performed differently in different versions of Android. It is best implemented in such a way that it covers most versions.

As others say, recycle () makes your bitmap unusable, recycle () is intended to be used after you finish with the bitmap, and would like to call garbage collection. I think you should use it in your onPause () / onStop () activity.

See here for more information: Raster Memory Management

0
source

Source: https://habr.com/ru/post/1497116/


All Articles