I load an image from url into an imageview in Activity 1 (using glide). When I switch to activity 2 ,I disconnect my network connection and I'm required to load the same image in another imageview. How am I supposed to achieve this? Can this be done by using the image cached somewhere by glide?
Asked
Active
Viewed 1,973 times
1
-
1this solution would be helpful https://stackoverflow.com/questions/32406489/glide-how-to-find-if-the-image-is-already-cached-and-use-the-cached-version – Ajay Venugopal Sep 25 '17 at 06:27
3 Answers
1
In your Activity1
Convert ImageView to Bitmap
imageView.buildDrawingCache();
Bitmap bmp = imageView.getDrawingCache();
Intent intent = new Intent(this, Activity2.class);
intent.putExtra("img", bmp);
In Activity2
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("img");
imageView.setImageBitmap(bitmap);

vishal jangid
- 2,967
- 16
- 22
0
Instead of caching image using glide create your own cache folder and cache images into it.It can be easily accessible throughout the application
Glide.with(yourImageView.getContext())
.load("your url")
.asBitmap()
.placeholder(R.drawable.place_holder)
.error(R.drawable.place_holder)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
//Create a folder for caching and add images from here
}
});

Sharath kumar
- 4,064
- 1
- 14
- 20
0
I use this and this works for me:
Add a OnClickListener like below:
Glide.with(this)
.load("URL HERE")
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(Image);
Image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(context,FullScreenImage.class);
intent.putExtra("image_url", "URL HERE" );
startActivity(intent);
}
});
Then in the new Activity:
public class FullScreenImage extends AppCompatActivity {
ImageView myImage;
String url = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_screen_image);
url = getIntent().getStringExtra("image_url");
myImage = findViewById(R.id.myImage);
Glide.with(this).load(url)
.placeholder(R.drawable.ic_image_send_24dp)
.error(R.drawable.ic_image_send_24dp)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(myImage);
}
}
PS: Dont forget to use .diskCacheStrategy(DiskCacheStrategy.ALL)
in both the activities while using glide.

Ashish Yadav
- 543
- 2
- 7
- 30