Android Image Caching

how to cache images?

Here is an example step-by-step on how to cache images, in memory and disk:

http://androidexample.com/Download_Images_From_Web_And_Lazy_Load_In_ListView_-_Android_Example/index.php?view=article_discription&aid=112&aaid=134

But you can also use libs that already work pretty well like :

http://square.github.io/picasso/

The first link also contains explanation on how you should treat bitmaps to avoid outOfMemory.

Coil image caching

Try disabling the cache headers support.

val imageLoader = ImageLoader.Builder(context)
.respectCacheHeaders(false)
.build()
Coil.setImageLoader(imageLoader)

Android Image caching

You can simple use Picasso library to handle this, it wil do everything for you

Picasso.with(context).load(R.drawable.drawableName).into(imageView);

In your adapter :

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if (convertView == null) {

holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_item, parent, false);
holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Picasso.with(context).load(R.drawable.drawableName).into(imageView);
return convertView;
}

class ViewHolder {
ImageView imageView;
}

Link: https://github.com/square/picasso

Or if you still not like to use Picasso, let's comment, i'll share you some class to modify image, save to cache and load up, but it so long...



Related Topics



Leave a reply



Submit