简体   繁体   English

Android:looper / handler与Java Observer?

[英]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? 如果某个服务需要了解服务何时有新的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(..) . 注册观察者只需调用一次 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). 处理程序允许您从后台线程修改UI组件,但处理/更新1个 “观察者”(由处理程序处理的那个)。

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. 更高级,如果你认为,你甚至可以将两者结合起来,永远是异常免费的,同时从后台线程更新UI仍然保持观察者模式。

I think nobody answered you in these 5 years because almost nobody is aware of great power of Observer pattern ;-) 我想在这5年里没有人回答你,因为几乎没有人知道观察者模式的巨大力量;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM