Giter VIP home page Giter VIP logo

livedatabus's Introduction

LiveDataBus

Android消息总线,基于LiveData,具有生命周期感知能力

简单之美

LiveDataBus的整个实现就一个类,不超过150行代码。不需要过于繁杂的功能,简单好用,就是最好的:)

使用方法

依赖

依赖Android Architecture Components,具体可参见gradle文件build.gradle

示例及Demo

订阅消息

  • observe模式 生命周期感知,不需要手动取消订阅
LiveDataBus.get()
	.with("key_name", String.class)
	.observe(this, new Observer<String>() {
	    @Override
	    public void onChanged(@Nullable String s) {
	       
	    }
	});
  • observeForever模式 需要手动取消订阅
LiveDataBus.get()
	.with("key_name", String.class)
	.observeForever(observer);
LiveDataBus.get()
	.with("key_name", String.class)
	.removeObserver(observer);

发送消息

  • set模式 订阅者会在当前线程收到消息
LiveDataBus.get().with("key_name").setValue(value);
  • post模式 订阅者会在主线程收到消息
LiveDataBus.get().with("key_name").postValue(value);

简单的Demo可参见:LiveDataBusDemo.java

文档

LiveDataBus实现原理

LiveDataBus的实现原理可参见作者在美团技术博客上的博文: Android消息总线的演进之路:用LiveDataBus替代RxBus、EventBus

其他

  • 欢迎提Issue与作者交流
  • 欢迎提Pull request,帮助 fix bug,增加新的feature,让LiveDataBus变得更强大、更好用

livedatabus's People

Contributors

jeremyliao avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.