java - Android Activity ASyncTask and onCancelled -


i have activity adds asynctask starts vector-list.

when activity destroyed goes through vector-list , calls oncancelled on asynctasks.

oncancelled called in each asynctask sets private fields null. these private fields referenced objects owned activity. asynctasks checking "iscancelled" means asynctasks stop in clean way.

each asynctask has reference vector-list.

this leaves remaining issues / questions:

  • since asynctask has bitten me in past: below questions, behavior consistent across api >= 8?

  • i assume oncancelled called if cancel called. means in such cases reasonable let activity maintain vector-list , null reference in asynctask?

  • in asynctask descendant, in thread oncancelled running? asynctask 1 or main-ui-activity 1 calling "cancel"? (this important thread safety of nulling private fields)

  • should each asynctask find , remove list when done , destroyed? assuming destructor runs in asynctask thread, need synchronize find/delete operation?

1)the inconsistency know of in asynctask execute being parallel vs being round robin on single thread , executeonexecutor being parallel.

2)yes, oncancelled called if cancel called. note docs: runs on ui thread after cancel(boolean) invoked , doinbackground(object[]) has finished.

this means oncancelled not called on thread.

3)ui thread, per docs

4)java doesn't have destructors. has finalizers, may never called, or may called 4 days now. cannot rely on them.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -