CHunky Universe of Vigourous Astonishing SHarepoint :)

Android: Asynchronously download images

In the Malmöfestivalen for Android where I participate we wanted to show thumbnails of events in lists. We have urls of thumbnails from Malmofestivalen API. This information is stored in a sqlite database and a SimpleCursorAdapter is used for getting the events from the database. It is possible to bind the urls to ImageView objects (by downloading the stream: 1, 2, 3). The problem is in a listactivity with many images it will freeze. So it must be an AsyncTask, and it should be some kind of local cache to avoid loading same images over and over again. Fortunately there is already ImageDownloader class provided in the android blog post: Multithreading For Performance .

The next step is to create custom adapter and extend from SimpleCursorAdapter: EventCursorAdapter, like described on Android-er and and SP-Technolab:

public class EventCursorAdapter extends SimpleCursorAdapter {
	private final ImageDownloader imageDownloader = new ImageDownloader();
	public EventCursorAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to) {		
		super(context, layout, c, from, to);
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = super.getView(position, convertView, parent);
		Cursor cursor = getCursor();

		ImageView iv = (ImageView) row.findViewById(;

		String url = cursor.getString(cursor.getColumnIndex(EventProvider.EVENT_KEY_URISMALLIIMAGE));
		if (url.length() > 0) {, iv);
		String start = cursor.getString(cursor.getColumnIndex(EventProvider.EVENT_KEY_STARTDATE));
		String end = cursor.getString(cursor.getColumnIndex(EventProvider.EVENT_KEY_ENDDATE));
		String dateString = DateHelper.createShortDateResume(start, end);
		TextView tv = (TextView) row.findViewById(;
		return row;

In this code the view is created by the super class and then it is modified, the alternative is to “inflate the view” completely self.

The result is an event list which opens directly and loads thumbnails asynchronously:

listactivity with images


4 responses to “Android: Asynchronously download images

  1. Justin Cooney 2012-04-26 at 16:32

    A very interesting example of how to download images asynchronously!

    • Anatoly Mironov 2012-04-26 at 16:58

      Thank you Justin! Glad you liked it. I think async is the only option we have nowadays 🙂

  2. matias elorriaga 2014-04-07 at 12:32

    this is an excellent article, but I have one question.. how do we handle device orientation changes? every time this happens, the listview re-download the images..

    • Anatoly Mironov 2014-04-07 at 12:35

      Good question. I have not thought about it. The view I had had only the vertical orientation. What happens on orientation change? Gets the view redrawed then?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Daniel Chronlund Cloud Tech Blog

News, tips and thoughts for Microsoft cloud fans

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager - Architect, Speaker, Author

Microsoft 365, SharePoint and Azure

SharePoint Dragons

Nikander & Margriet on SharePoint

Mai Omar Desouki

PFE @ Microsoft

Cameron Dwyer

Office 365, SharePoint, Azure, OnePlace Solutions & Life's Other Little Wonders


Me and My doings!

Share SharePoint Points !

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

DevOps, Cloud and Blockchain Consultant


SharePoint for everyone


Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint


Mostly what I know and share about...

%d bloggers like this: