大佬教程收集整理的这篇文章主要介绍了android – Picasso绑定适配器’连接被泄露’消息,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
问题来自死图像链接,硬编码我的所有图像网址指向无处不在为屏幕上的第一对滚动后的每个图像产生错误.
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'
@Override public Result load(request request,int networkPolicy) throws IOException { okhttp3.request downloaderrequest = createrequest(request,networkPolicy); Response response = downloader.load(downloaderrequest); ResponseBody body = response.body(); if (!response.issuccessful()) { body.close(); throw new ResponseException(response.code(),request.networkPolicy); } // Cache response is only null when the response comes fully from the network. Both completely // cached and conditionally cached responses will have a non-null cache response. PiCasso.LoadedFrom loadedFrom = response.cacheResponse() == null ? NETWORK : DISK; // Sometimes response content length is zero when requests are being replayed. Haven't found // root cause to this but retrying the request seems safe to do so. if (loadedFrom == DISK && body.contentLength() == 0) { body.close(); throw new ContentLengthException("Received response with 0 content-length header."); } if (loadedFrom == NETWORK && body.contentLength() > 0) { stats.dispatchDownloadFinished(body.contentLength()); } InputStream is = body.byteStream(); return new Result(is,loadedFrom); }
我对PiCasso项目并不太熟悉,但似乎在所有情况下都没有关闭响应体对象.你可能已经发现了毕加索的一个错误,可能想在毕加索的github上提出一个问题
以上是大佬教程为你收集整理的android – Picasso绑定适配器’连接被泄露’消息全部内容,希望文章能够帮你解决android – Picasso绑定适配器’连接被泄露’消息所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。