Hi i am new beginner in android. I want to insert image in imageView from URL but whenever one time it is loaded from URL in imageView then second time it should be insert without internet means it would be stored in cache as well.
Asked
Active
Viewed 1.3k times
10
-
so what have you done so far ? – Shahzeb Oct 05 '15 at 04:40
-
use fresco, it is image loading library of facebook and seems good to me https://github.com/facebook/fresco – Syed Raza Mehdi Oct 05 '15 at 05:29
-
Checkout this if you are looking for diskcache http://stackoverflow.com/a/32516598/1939564 and this if you are looking for memory cache http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html – Muhammad Babar Oct 05 '15 at 07:20
4 Answers
13
for this you can use picasso Library You can download it from Picasso Library site simply put this jar file into libs folder. It will manage all property of Image. http://square.github.io/picasso/
String imgURL = "Your URL";
ivmage = (ImageView) findViewById(R.id.imageView1);
Picasso.with(MainActivity.this).load(imgURL).into(ivmage);

Sam
- 462
- 2
- 13
4
You can use Picasso
Library.
By Using Picasso
, The Advantages are
- Handling ImageView recycling and download cancelation in an adapter.
- Complex image transformations with minimal memory use.
- Automatic memory and disk caching.
To load Image
from Url
Picasso.with(context).load(url).into(imageView);
Refer this link for Api : Picasso

Rajan Kali
- 12,627
- 3
- 25
- 37
2
you can use Glide https://github.com/bumptech/glide
Glide.with(this).load("imageURl").into(imageView);

Ashish Agrawal
- 1,977
- 2
- 18
- 32
1
I suggest picasso library for doing this. here is the detailed documentation of picasso library.
ex:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
or you can make use of volley's ImageLoader. here you can find the documentation for Volley's image loading.
ex :
// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap bitmap) {
mImageView.setImageBitmap(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
mImageView.setImageResource(R.drawable.image_load_error);
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);
if you are using volley. then you have to cache images manually. picasso will cache images by default.

droidev
- 7,352
- 11
- 62
- 94