Git Product home page Git Product logo

rxbus's People

Contributors

wzgiceman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rxbus's Issues

在多个页面register同一event的消息,发送消息会导致该event类型的集合被多次遍历执行

例如我在A,B两个页面都register一个string类型的event,在C页面post一个string消息后,会invoke四次.
第一次:subscriber A触发,在rxbus中的callEvent这个中会得到List,A,B都在该list中,所以遍历的时候回执行2次invoke,
第二次subscriber B同理触发了2次,总计为4次.
在我看来subscriber A只观察A中注册的event,B只观察B中注册的event,而不应该是A接收消息时会附带执行B中同类型的event.这样A,B只关心自己的event,A+B总体上来看同一event还是被遍历一次而不影响以前的逻辑,多以在callEvent过滤掉部分事件即可.

/**
 * 回调到订阅者的方法中
 *
 * @param code       code
 * @param object     obj为event的类型
 * @param subscriber 注册消息时的订阅者对象
 */
private void callEvent(int code, Object object, Object subscriber) {
    Class eventClass = object.getClass();
    //获取event类型的所有方法
    List<SubscriberMethod> methods = subscriberMethodByEventType.get(eventClass);
    if (methods != null && methods.size() > 0) {
        for (SubscriberMethod subscriberMethod : methods) {
          //订阅者和注册消息时的订阅者对象为同一对象时才执行该方法体
            if (subscriberMethod.subscriber == subscriber) {
                //......原来for中的逻辑
            }
        }
    }
}

调用的地方就为:callEvent(subscriberMethod.code, o,subscriberMethod.subscriber);
这样就可以多次被触发

Service中二次接收消息失败

在Service注册Rxbus后,在一个页面发送消息Service能收到消息,退出页面后重新进入,再次发送,Service无法收到消息

发送消息不成功

case R.id.btn_sticky: RxBus.getDefault().post(new EventStickText("我是sticky消息")); Intent intent = new Intent(this, Main2Activity.class); startActivity(intent); break;
一加手机,7.0系统 没有效果

出现rx.exceptions.OnErrorNotImplementedException

在post事件时报错, 看了下应该是
// 主题
private final Subject bus;
这里没有泛型导致类型检查错误,然后没有onError处理导致异常
加上泛型后正常了
private final Subject<Object, Object> bus;

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.