Search code examples
androidandroid-intentpicasso

passing image fetched from a remote source in an activity to another activity using picasso


I'm a beginner in android development.I've a set images fetched from a URL into an Activity 'A' using Picasso, and are arranged in a GridView. Now, I want to pass the image which the user has tapped on, into an Intent. How can I pass the one of the fetched image to another activity, without having to fetch the image again.

Please help me.

Thank you.


Solution

  • If you are trying to reuse an image fetched in ActivityA in ActivityB without fetching again, you don't have to do anything apart from calling

    Picasso.with(context).load(url).into(imageView)
    

    at both places.

    If the url parameter is the same for both the activities, Picasso automatically fetches the image from cache(where it got stored when you called load in ActivityA) instead of making another network call.

    Picasso automatically caches your image in the RAM, and uses okhttp internally to cache it in the disk. So, you don't have to pass it explicitly through an intent.

    To check where it got loaded from, you can call

    Picasso.with(getContext()).setIndicatorsEnabled(true).
    

    This will put a colored flag on the top-left corner of every image.

    Red means it was called fetched from the network.

    Blue- disk.

    Green- RAM.

    In ActivityA, it should be Red since you're loading it from the network. In ActivityB, it should be Green(or blue), since you're fetching it from the cache.