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?
yes, each grid item child
view
.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 twentyasynctask
s, few of them executing @ time. @ same time, since eachasynctask
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 adapterview
s, recycle child views don't need initialize new view
s 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
Post a Comment