我很好奇,所以我安裝了NPR新聞應用程序,並得到複製你的錯誤。
從我所瞭解的情況來看,他們在網絡適配器中緩存Bitmaps,並且只要緩存需要再次下載這些位圖(無論什麼原因),它就會掛起。事情是,在持續的滾動事件中,你需要一次滾動多個列表項,所以如果一個項需要刷新它的緩存值,那麼其他項也需要它。根據適配器的實現,可能會發生一些奇怪的併發修改。
下面是它掛起時會發生什麼的痕跡:適配器越來越混亂。
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
我的建議:使用佔位符?讓適配器只從緩存中獲取,找不到找到的佔位符,並在緩存無效時觸發後臺線程操作。
似乎是一個Android錯誤的樣品佈局。升級到2.3.4後不再可重現。 – kimkunjj 2011-12-27 01:07:47