Lets say my Activity has a list object containing stuff. This Activity starts off several AsyncTasks. When these tasks finish, they modify this list (add stuff in it for example), in their postExecute() methods. Should this list be thread-safe?
My bet is that it's not neccesary, because the code in the postExecute() methods run in the UI thread, sequentially. So they don't get to modify the list in parallel. Is this correct?
Yes, you are correct. The postExecute() is executed in the UI thread so all your AsyncTasks will update your list sequentially (and not at the same time).
In other situations I'd advise you to have a look into synchronizedList of Java's Collections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With