I have a listadapter, where I have many listitems, every item contains a textview and a imageview. I would like to download the images (encoded in Base64) from the backend, so Picasso and the via URL downloading solutions are not good for me. After I downloaded the Base64 decode and Bitmap creation is already done, I`m just stuck how to start a background thread in a list adapter, where views are always recycling (when user scrolls).
I started to created a Thread with a Hanlder, where handler inserted the bitmap to the imageview, but it didn`t worked (out of memoryE). After it I fired an AsyncTask, but in this case I have the recycle problem, namley: when the user scroll down, I see the top image in a bottom view :(
using retrofit for downloading
Can you help me please ?
Code of my AsyncTaks: The problem here, I update the imageview, but maybe the user are already scrolled away!
public DownloadImageAsyncTask(ImageView iw, Display display, String imageID, ImagesCache imagesCache) { this.iw = iw; this.imageCache = imagesCache; this.imageID = imageID; this.display = display; }
@Override
protected Void doInBackground(Void... params) {
String[] imageArray = new String[1];
imageArray[0] = imageID;
ImageResponse imageResponse = new IdeaBackend().getImageByID(imageArray);
bitmap = UserExperienceHelper.decodeBase64AndScaleDownImage(imageResponse.getResponse().get(0).getImageBase64Code(), display);
imageCache.put(imageID, bitmap);
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
this.iw.setImageBitmap(bitmap);
}
You need to recycle bitmaps or views. Incremental loading of listviews can easily be handled. Here's a post that might help you!
Optimized, Incremental Access to ListView.
Endless Scrolling with adapter views