GithubHelp home page GithubHelp logo

myeventbuslib's Introduction

myeventbuslib

仿eventbus,简化eventbus流程,让框架结构更加清晰

博客地址:https://www.cnblogs.com/tony-yang-flutter/p/12463490.html

用法: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** * 注册观察者对象 */ EventBus.getDefault().register(this); btn = findViewById(R.id.main_btn); tv = findViewById(R.id.main_tv); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toPost(); } });

}

/**
 * 用于接收post发送过来的事件
 *
 * @param event 具体的事件主体
 */
@Subscribe
public void onMessageEvent(MessageEvent event) {
    switch (event.getArg1()) {
        case 0:
            tv.setText("接收小消息为:" + event.getMsg());
            break;

    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    /**
     * 取消订阅
     */
    EventBus.getDefault().unRegister(this);
}

/**
 * 发送消息
 */
public void toPost() {
    MessageEvent event = new MessageEvent();
    event.setArg1(0);
    event.setMsg("杨洛峋小宝宝来了");
    EventBus.getDefault().post(event);
}

}

myeventbuslib's People

Contributors

ywtony avatar

Watchers

James Cloos avatar  avatar

myeventbuslib's Issues

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.