开发者

AsyncTasks and thread-safe data objects?

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 开发者_如何学Cthe 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜