androidfetchpicassoimage-preloader

how to pre-dowload images using picasso android?


I am implementing a kind of tab like browsing in android using Picasso, whenever a tab is selected the Picasso code to get it from the URL is called. I want to make it more user friendly and download all of the images to the device so that selecting different tabs will be from the device not the internet.

Is there a Picasso command to cache URL for later use? Even when using it from different fragments or activity?

I have tried:

Picasso.with(this).load(URL).fetch();

but it does not seem to work as smoothly...


Solution

  • Actually fetch() works like a charm. Here is my Activity's code.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Picasso.with(this).load(URL).fetch();
    }
    

    After the app was run, image had been downloaded successfully and was cached like it supposes to be.

    enter image description here

    So the problem is not that line of code. It might be from another reason, for example, you forgot to add INTERNET permission in your manifest or the image in that URL is not existed.