Search code examples
androidsingletonpicasso

Picasso Singleton Usage


I am using Picasso in my app.

First, I only use the format below:

Picasso.with(context)....into(imgView);

This way I assume I use Picasso as a singleton. Do I?

Second, I want to use setIndicatorsEnabled. However it cannot be added to the format above since it is not a static method. Is there any way to use this function in the format above?

Third, if I need to create a custom instance using Picasso.Builder(...).build() in order to use setIndicatorsEnabled, what is the best way to achieve singleton usage across the activities of the app?


Solution

  • Yes you assume Picasso is a singleton instance when you use Picasso.with(context)....

    to use set indicators enabled

    Picasso mPicasso = Picasso.with(context);
    mPicasso.setIndicatorsEnabled(true);
    mPicasso....load().into(imageView);
    

    if you use the builder you should create your own singleton to hold your instance of Picasso and clean it up when your done. Do not use builder every time that you use picasso because it creates a new instance. I believe that Picasso.with(context) just takes your context and calls getApplicationContext and stores a singleton instance of picasso with the application context.