android发布/订阅模式 [英] android publish/subscribe pattern

查看:56
本文介绍了android发布/订阅模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android 中有发布/订阅模式吗?

我想要实现的是我有这个类可以通知感兴趣的一方事件.然后感兴趣的一方可以为所欲为.

来自 .net microsoft 世界,这种东西是内置的.

android 有没有类似的东西,或者我必须写一些类似观察者模式的东西?

解决方案

我认为您说的是在应用程序中的类之间传递事件/消息.所以这个问题可能归结为这种模式的 Java 实现.

实际上并没有内置任何东西(即没有 event 系统类),让类传播事件/消息的最常见方法之一是 Listener 技术(参见维基百科Vogel, IBM).

也有框架,从这个SO answer开始.>

如果您担心 Android 中线程/进程之间的异步消息,那么有 处理程序AsyncTasks 和(用于互process) Parcelables.

Is there a publish/subscribe pattern in android?

What I want to achieve is I have this class that can notify interested party of an event. Then the interested party can do whatever it needs.

Coming from a .net microsoft world, this sort of thing are build in.

Do android have something similar, or I have to write some thing like an observer pattern?

解决方案

I think you are speaking in terms of passing events/messages among classes within your application. So this question probably goes down to Java implementation of such a pattern.

There's nothing actually already baked in (i.e. no event system class), one of the most common way to let a class spread an event/message is the Listener technique (see wikipedia, Vogel, IBM).

There are frameworks too, as from this SO answer.

If you are concerned about asynch messages between thread/processes in Android, then there are Handlers, AsyncTasks and (for inter-process) Parcelables.

这篇关于android发布/订阅模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆