在Picasso.with(context)
..爲什麼在畢加索(背景)中,畢加索要求上下文?
public static Picasso with(Context context) {
if (singleton == null) {
synchronized (Picasso.class) {
if (singleton == null) {
singleton = new Builder(context).build();
}
}
}
return singleton;
}
和建造(上下文的背景下),這樣
/** Start building a new {@link Picasso} instance. */
public Builder(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context must not be null.");
}
this.context = context.getApplicationContext();
}
爲什麼畢加索甚至要求的上下文時,它總是setting context = context.getApplicationContext()
?
它還可以防止通過切換到應用程序上下文來泄漏「活動」(如果這就是你所傳遞的)。 –
非常感謝@JakeWharton! –