バインディングアダプタを使用して、リサイクラビューで画像を読み込み中です。画像は正常に表示されます。早速スクロールしながら、私はときどきピカソから「接続漏れ」のメッセージを受け取りました。Picassoバインディングアダプタ '接続がリークされました'メッセージ
問題はデッド・イメージ・リンクに由来し、すべての画像URLをハードコーディングすると、画像のすべてが画面上の最初のカップルをスクロールしてエラーを生成します。。
W/OkHttpClient: A connection to https://s3-eu-west-1.amazonaws.com/ was leaked. Did you forget to close a response body?
コードは基本的にはto this sampleと同じです。
BindingUtils.kt
object BindingUtils {
@BindingAdapter("imageUrl")
@JvmStatic
fun setImageUrl(imageView: ImageView, url: String) {
Picasso.with(imageView.context).load(url).into(imageView)
}
XML
<ImageView
android:id="@+id/imageview_merchant_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary"
android:scaleType="centerCrop"
app:imageUrl="@{viewModel.background}"/>
のGradle
implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$rootProject.okhttpLoggingVersion"
implementation "com.squareup.picasso:picasso:$rootProject.picassoVersion"
retrofitVersion = '2.3.0'
okhttpLoggingVersion = '3.6.0'
picassoVersion = '2.5.2'
私は標準Okhttp要求のための接続を閉じるが、そのピカソと見に必要としている人々には、いくつかの文献を参照することができますロード・コールは1ライナーです。これがどのように漏れているのでしょうか?
たぶん、あなたは新しいものを呼び出す前に、前の要求をキャンセルしなければならないとしてみてください。Picasso.with(コンテキスト).cancelRequest(ImageViewの); –