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