我很好奇,所以我安装了 NPR 新闻应用程序并复制了你的错误。
据我了解,他们正在他们的适配器中缓存来自网络的位图,并且只要缓存需要再次下载这些位图(无论出于何种原因),它就会挂起。问题是,在连续滚动事件中,您应该一次滚动浏览多个列表项,因此如果一个项目需要刷新其缓存值,则其他项目很可能也需要它。根据适配器的实现,可能会发生一些奇怪的并发修改。
这是挂起时发生的事情的痕迹:适配器变得非常混乱。
05-21 08:53:07.570: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/machoman_sq.jpg?t=1305913905&s=12
05-21 08:53:07.580: DEBUG/org.npr.android.util.PlaylistProvider(6457): content://org.npr.android.util.Playlist;story_id = ?;[136497574]
05-21 08:53:07.580: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/pelosi_flex.jpg?t=1305924952&s=12
05-21 08:53:07.610: DEBUG/org.npr.android.news.DownloadDrawable(6457): Got bitmap
05-21 08:53:07.610: DEBUG/org.npr.android.news.DownloadDrawable(6457): Download complete
05-21 08:53:07.610: DEBUG/org.npr.android.news.DownloadDrawable(6457): Starting download
05-21 08:53:07.620: DEBUG/org.npr.android.util.PlaylistProvider(6457): content://org.npr.android.util.Playlist;story_id = ?;[136507004]
05-21 08:53:07.620: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/capitol.jpg?t=1305929989&s=12
05-21 08:53:07.630: DEBUG/org.npr.android.util.PlaylistProvider(6457): content://org.npr.android.util.Playlist;story_id = ?;[136498068]
05-21 08:53:07.630: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/ppw1.jpg?t=1305913144&s=12
05-21 08:53:07.640: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/levee.jpg?t=1305901869&s=12
05-21 08:53:07.670: WARN/org.npr.android.news.NewsListAdapter(6457): Could not find list item at position 27
05-21 08:53:07.680: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/imf.jpg?t=1305915244&s=12
05-21 08:53:07.710: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/syria.jpg?t=1305904814&s=12
05-21 08:53:07.750: DEBUG/org.npr.android.news.ImageThreadLoader(6457): Cache hit: http://media.npr.org/assets/img/2011/05/20/netanyahu.jpg?t=1305900960&s=12
05-21 08:53:07.850: DEBUG/org.npr.android.news.DownloadDrawable(6457): Got bitmap
05-21 08:53:07.850: DEBUG/org.npr.android.news.DownloadDrawable(6457): Download complete
05-21 08:53:07.860: DEBUG/org.npr.android.news.DownloadDrawable(6457): Starting download
05-21 08:53:07.880: WARN/org.npr.android.news.NewsListAdapter(6457): Could not find list item at position 28
05-21 08:53:08.510: DEBUG/org.npr.android.news.DownloadDrawable(6457): Got bitmap
05-21 08:53:08.510: DEBUG/org.npr.android.news.DownloadDrawable(6457): Download complete
05-21 08:53:08.550: WARN/org.npr.android.news.NewsListAdapter(6457): Could not find list item at position 29
我的建议:使用占位符?让适配器仅从缓存中获取,在未找到占位符时检索占位符,并在缓存无效时触发后台线程操作。