Awesome Open Source
Awesome Open Source

Latest version

router 1.2.8 —— modified code to avoid concurrent bugs

router 1.2.6 -- use apt to process subscribe annotation

router 1.2.0 -- use WeakReference to avoid MemoryLeak cause by forgot unregister


It had been used in project KnowWeather and diffadapter demo ,you can learn more.

What's Router

English | 中文文档

Router -- A substitute good of EventBus similar implemented by dynamic proxy

dynamic proxy

what's dynamic proxy and how to use , see my blog 代理模式的学习与应用


EventBus is good ,but there are some problems when use.

  • EventBus is not friendly to IDE such as on registered method ,control+click(or other shortcut key) can't take you to what's actually being called , and there no any prompt when you post a event even you get a mistake.

  • when called post(Event event),EventBus use Event type to find the received method ,so you must define many class for different received methods to avoid invoked unexpected even they have same class type or you only want dispatch a base type such as a int value

above all , when project gets larger or multiple developers work on project,which greatly increases the cost of developing and maintaining.


  • take even no time and memory when register , only add a object reference to a map.
  • friendly to IDE, you can easily find the action from where it was called. and when you try to send a event there while be a prompt by ide.
  • defined method to match event instead of many methods.
  • both Router and MVP design model using implement interface as a way of communication ,so it fit perfectly in MVP .
  • proven in practice by mature apps.


Router is easily use especially when you had used EventBus before.

Step1. define interface and method whatever you want

interface AnyInterface {
    void anyMethod(AnyType posting) ;

Step2. register to Router where you need implement the interface

class AnyClass implement AnyInterface {

    //register on a appropriate lifecycle or constructor
    //it will be invoked on UI Thread
    void anyMethod(AnyType object)  {
        //do what you want

Step3. invoke the method you defined before

Router.getInstance().getReceiver(AnyInterface.class).anyMethod(AnyType object);

Step4. unregister when not use anymore or a appropriate lifecycle


now a publish/subscribe is completed,simple as EventBus.

Method Invoked Thread

Use Annotation invoke method in different threads

 @Subscribe(runThread = RunThread.MAIN)
 @Subscribe(runThread = RunThread.POSTING)
 @Subscribe(runThread = RunThread.ASYNC)
 @Subscribe(runThread = RunThread.BACKGROUND)

Just like EventBus's way to reduce learning cost. if not add Annotation, will use @Subscribe(runThread = RunThread.Main) as default.

Annotation Mode

mode 1 :add Annotation on implemented method, it as default
@Subscribe(runThread = RunThread.BACKGROUND)
public void anyMethod(String msg) {

anyMethod will invoked on RunThread.BACKGROUND thread

mode 2 :add Annotation on interface's method

interface TestRunThread {
     @Subscribe(runThread = RunThread.POSTING)
     void anyMethod(String posting) ;

on this mode, all class which implement the method will be invoked on the RunThread.POSTING thread.

more use details , see the simple.

Add to project


compile 'com.silencedut:router:1.2.8'




Copyright 2015-2016 SilenceDut

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.

Alternative Project Comparisons
Related Awesome Lists
Top Programming Languages

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Java (404,512
Router (13,762
Thread (12,390
Annotations (10,972
Eventbus (1,529
Dynamic Proxy (28