On the message mechanism of open source class library Eventbus

Source: Internet
Author: User

Eventbus is based on the message delivery mechanism of Otto, through the open source of the Great God's package, has become more and more useful.


Send message (must send message in main thread, send message can not register bus)
Eventbus.getdefault (). Post ();


Accept message (must accept message in main thread, accept message must register bus)
public void OnEvent () {}


Register Bus
Eventbus.getdefault (). Register (this);


Ex

Package com.woyou.utils.eventbus;/** * Otto Event Abstraction * * @author longtao.li * */public interface ievent<t> {int getId () ; void setId (int id); T getData ();} Package Com.woyou.utils.eventbus;import com.woyou.model.goods;/** * Show event notification for property layout * @author Longtao.li * */public Class Eventshowprop implements Ievent<goods>{private Goods goods;public eventshowprop (Goods Goods) {this.goods = Goods;} @Overridepublic int getId () {//TODO auto-generated method Stubreturn 0;} @Overridepublic void setId (int id) {//TODO auto-generated method stub} @Overridepublic Goods GetData () {return Goods;}} Eventshowprop Eventshowprop = new Eventshowprop (goods); Eventbus.getdefault (). Post (Eventshowprop);/** * Display select attribute Layout * @param event */eventshowprop eventshowprop;public void Onev ENT (Eventshowprop event) {if (Eventshowprop = = event) {return;} LOG.I (TAG, "Eventshowprop"); This.eventshowprop = Event;propertylayout.showpropview (Event.getdata (), NULL); Propertylayout.setvisibility (view.visible);}

About its jar package, address: http://download.csdn.net/detail/u012301841/8456735

On the message mechanism of open source class library Eventbus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.