Picasso and context

前端 未结 1 929
忘掉有多难
忘掉有多难 2021-02-13 20:56

I have been playing lately with Picasso as an image loader library. I use it in conjunction with Dagger and OkHtttp.

My only questions regarding this library are the us

1条回答
  •  既然无缘
    2021-02-13 21:24

    It doesn't matter which you choose, when using the default Picasso.with(Context) method, or the Builder, it will retrieve the application Context from the given Context:

    /** 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();
    }
    

    Stub copied from Picasso.java#Builder.


    If you actually want to create a new instance in each activity: For each instance of Picasso you create, you basically create a new cache: images cached in the first instance will not be reused in the second instance. You are very likely to run into OutOfMemoryExceptions here, as Picasso does not handle this.

    0 讨论(0)
提交回复
热议问题