Picasso is designed as a singleton, so every new instance is not created every time.
This is the with() method:
public static Picasso with(Context context) { if (singleton == null) { synchronized (Picasso.class) { if (singleton == null) { singleton = new Builder(context).build(); } } } return singleton; }
Note that this is a static method, so you do not call with() on a specific instance, Picasso manages its own instance, which is only created if singleton is null .
There is no problem passing Activity as a context, because the Builder will use the ApplicationContext, which is a single, global Application object of the current process :
public Builder(Context context) { if (context == null) { throw new IllegalArgumentException("Context must not be null."); } this.context = context.getApplicationContext(); }
As for the cache, the same one is used every time, since it is stored in singleton:
public Picasso build() { // code removed for clarity if (cache == null) { cache = new LruCache(context); } // code removed for clarity return new Picasso(context, dispatcher, cache, listener, transformer, requestHandlers, stats, defaultBitmapConfig, indicatorsEnabled, loggingEnabled); }
source share