Picasso Singleton用法

Meh*_*med 8 singleton android picasso

我在我的应用程序中使用Picasso.

首先,我只使用以下格式:

Picasso.with(context)....into(imgView);
Run Code Online (Sandbox Code Playgroud)

这样我认为我使用毕加索作为单身人士.我呢?

其次,我想用setIndicatorsEnabled.但是它不能添加到上面的格式,因为它不是静态方法.有没有办法以上面的格式使用此功能?

第三,如果我需要创建使用自定义的情况下Picasso.Builder(...).build()才能使用setIndicatorsEnabled,什么是实现跨应用程序的活动单使用的最佳方法?

dou*_*leA 10

是的,当你使用Picasso.with(context)时,你认为Picasso是一个单例实例....

使用设置指示器

Picasso mPicasso = Picasso.with(context);
mPicasso.setIndicatorsEnabled(true);
mPicasso....load().into(imageView);
Run Code Online (Sandbox Code Playgroud)

如果您使用构建器,您应该创建自己的单例来保存您的Picasso实例并在完成后清理它.每次使用毕加索时都不要使用构建器,因为它会创建一个新实例.我相信Picasso.with(context)只需要你的上下文并调用getApplicationContext并将picasso的单例实例与应用程序上下文一起存储.