Now a days every app has to load some sort of images, from servers so this has become a crucial for every app developer to be careful in handling these situations, which are covered in this tutorial on Android tutorial on Picasso library.

Load image using Picasso is quite easier and also flexible when compared to the routine manual way of downloading it and setting it up to the view.

The scenarios can be further divided into sending a request to server and getting the link parsing and fetching image from the link. This may take a few moments of time though considering the speed of network and device used so to handle this time there can be a default image shown till the actual image is loaded. You may consider this as default image which shows loading.

Also a lot more other thing which we may not notice generally if you are new to programming, i.e., “cache” this plays a key role when you focus much on app performance and speed of the app.This can be achieved using this Picasso library even a novice can easily integrate it into their app and can benefited from it.

1)  Uses less memory as it uses concept of recycling.

2) Maintains cache which will let you load images faster every time.

3) You can load a image from url, or from local resource

4) Place a loading image so that user will know that image is going to load in few moments.

5) Also if the image is not available at the source then no worry it will display a error image which you specify this is an added advantage to handle these situations.

 

These are all the basic things regarding image loading but which are also tough for a beginner to handle.

 

 

lets start coding…

Add Picasso library to your project –> build.gradle (Module.App)

then

 

activity_main

Now start with the common thing which we need to load image i.e., Android ImageView

 

its common thing lets move on to loading image

 

MainActivity

Initialize image view

 

initialize Picasso Library

 

then to load image using url

 

or you can even load a image from local resource drawable folder

 

the till the image comes up you may show a placeholder image this will be replaced once image is loaded

 

if unfortunately image you specified is not available at source then an error image can be displayed as

 

this view is to be binded with imageView

 

Finally,

 

Manifest

 

Add internet permission to your manifest file if necessary.

 

Show Buttons
Hide Buttons
Read previous post:
Know your android app version || app version

Close