开发者

Android: looper/handler vs. Java Observer?

Aren't these competitors? I开发者_高级运维'm thinkin they're not, but don't see it.

How about within the context of an Activity needing to learn when a Service has new xyz?

Thanks!


They are for different purpose so you can't compare in the way that one exclude the other as perhaps you may intend. I explain:

  • Registered Observers receive notification of a change all together sequentially simply calling once notifyObservers(..).

  • Handlers allow you to modify UI components from a background thread but you handle/update only 1 "observer" (the one handled by the Handler).

More advanced, if you think, you can even combine the two, to always be exception free while update UI from a background thread still keeping the Observer pattern.

I think nobody answered you in these 5 years because almost nobody is aware of great power of Observer pattern ;-)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜