MicroBus - DEPRECATED

Android Arsenal

The event bus is considered to be an anti-pattern now. Thus, I mark it as deprecated now.

Code that relies heavily on using a bus is an unsupportable mess. Use Observable-Observer patters instead, RxJava preferable.

USAGE

Initialization:

MicroBus bus = new MicroBus();

Definition of a message:

public class Hello {
    public String name;

    public Hello(String name) {
        this.name = name;
    }
}

Receiving class:

class Receiver implements MicroBus.BusEventReceiver {

    public onCreate() {
        bus.register(this, Hello.class);
    }

    public onDestroy() {
        bus.unregister(this, Hello.class);
    }

    @Override
    public void onBusEvent(Object event) {
        if (event instanceof Hello)
            System.out.println("Hello, " + ((Hello)event).name + "!");
    }
}

Sending:

	    bus.post(new Hello("Joe"));

Output:

Hello, Joe!

LICENSE

http://www.apache.org/licenses/LICENSE-2.0

(c) 2014 Konstantin Mikheev

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT