Downloading and Caching Images in Android

30 January 2015 by Daniel Sprowls

When there are so many Android applications available to consumers, how can a developer make sure their application stands out from the rest of the crowd? One sure way to do this is to make your application look more visually appealing to users. Graphical assets can add a lot of character and style to an application, so naturally developers take advantage of them to provide the best possible user experience. Displaying images stored directly in an Android application is a pretty simple task, but what happens when a developer wants to download, display, and cache an image stored at a particular URL? This process can be tricky and sometimes a bit messy. There are several open source libraries designed to make handling graphical assets much easier, but this blog post will focus on Picasso.

Picasso packs an incredible amount of power and functionality in a very concise form. You can load an image from a URL, cache that image into memory and onto the disk, choose which ImageView to load the image into, resize the image, and display a placeholder image while the image loads - all from a single statement via method chaining.

This statement will automatically cache the image to both memory and disk and automatically handle all threading involved.

        .resize(250, 250)      

Picasso removes a tremendous amount of overhead involved in managing image resources and simplifies complex tasks such as caching, threading, and networking. Instead of taking the time to write all of this code by hand and troubling yourself with these tedious tasks, try out Picasso.

Be sure to check out the repo.

Let's build your next big thing.

Contact Us