android - Handle Concurrency for GridView when used in conjunction with AsyncTask -


i'm reading chapter processing bitmaps off ui thread in android training. in chapter, author talks handling concurrency gridview when used in conjunction asynctask:

common view components such listview , gridview introduce issue when used in conjunction asynctask demonstrated in previous section. in order efficient memory, these components recycle child views user scrolls. if each child view triggers asynctask, there no guarantee when completes, associated view has not been recycled use in child view. furthermore, there no guarantee order in asynchronous tasks started order complete.

for above paragraph, have 2 questions:

(1) what's child view of gridview? take following figure example, every grid child view?

(2) i'm confused "if each child view triggers asynctask, there no guarantee when completes, associated view has not been recycled use in child view." can explains more detail? example, grid[1,1] triggers asynctask, when asynctask finishes, why there may incur problem?

enter image description here

  1. yes, each grid item child view.

  2. the main purpose of asynctask process long-running jobs off main thread ui doesn't hang. internally, asynctask uses threadpoolexecutor fixed number of threads manage tasks. if fire off twenty asynctasks, few of them executing @ time. @ same time, since each asynctask runs in it's own thread, might finish @ time depending on how system decides schedule thread. there no guarantee tasks finish in same order.

when process images off main thread, need consider following scenario.

in adapterviews, recycle child views don't need initialize new views every time view scrolled on screen. happen in case child view trigger asynctask fetch image when appears on screen.

but before image fetched, user continues scrolling , view scrolls off screen , appears again on other side(because recycling views). now, triggers asynctask fetch image supposed display. @ same time, earlier asynctask associated view completes , sets image view, if isn't right position image.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -