Teeps

Downloading and Caching Images in Android

30 January 2015 by Daniel Sprowls

Cfb109ef9f32e4a7fbd49a9034b30a646aedf418

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.

Picasso.with(context)
      .load(profileImageUrl)
      .resize(250, 250)
      .placeHolder(R.drawable.image_place_holder)
      .into(profileImageView);

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