如果你要一对多的发布广播消息,可以使用EventBus这个库。
现在是这样的一个场景,第一个页面跳转到第二个页面,第二个页面点击按钮返回的同时,将页面编辑框里面的字符串传给页面一。
一、添加依赖

二、创建一个消息实体类

三、页面一里在适当的地方,注册、取消注册EventBus,并创建接收信息的方法(方法上面要添加@Subscribe注释和threadMode),如下图:

四、页面二里面当点击返回按钮的时候,通过EventBus方法发送这个消息实体

此时,页面一就会显示这个Toast消息了,效果如下:

比较简单哈,想要了解EventBus更多信息,看EventBus Document
网友评论