NO1:
Eventbus three elements:
1) Event: Events
2) Subscriber: Event subscribers
3) Publisher: Event Publisher
No2:
Eventbus 4 Types of Threadmode (threading model):
1) POSTING (default): Which thread the event is published on, and in which thread the event handler will run
2) MAIN: Handling of events is performed in the UI thread
3) BACKGROUND: Execute in New thread or sub-thread released, disable UI update operation
4) ASYNC: Execute in New child thread, disable UI update operation
No3:
Eventbus Source Code Analysis
Eventbus.getdefault () (singleton mode)
New Eventbus ()
Eventbus (eventbusbuilder) (builder mode)
Register->
Subscribermethodfinder.findsubscribermethods->findusinginfo->getsubscriberinfo-> Findusingreflectioninsingleclass->
Subscribe->
...
No4:
Otto Use
Compile ' com.squareup:otto:1.3.8 '
Public class busdata{ public String message; Public busdata (String message) { this. Message = message; } Public String getMessage () { return message; } Public void setmessage (String message) { this. Message = message; }}
Public classOttobusextendsbus{Private volatile StaticOttobus Bus; PrivateOttobus () {} Public StaticOttobus getinstance () {if(Bus = =NULL){ synchronized(Ottobus.class){ if(bus==NULL) {Bus=NewOttobus (); } } } returnbus; }}
Bus bus = ottobus.getinstance (); Bus.register (this), Bus.unregister (this); @ Subscribepublicvoid setcontent (busdata data) { Tv_message.settext (data.getmessage ( ));} Ottobus.getinstance (). Post (new busdata ("Liu Wangshu's Blog updated"));
NO5:
Functions of Otto Main class
1) Produce, Subscribe: Publisher and Subscriber note classes
2) Bus: Event Bus class, used to register and unregister, maintain publish-subscribe model, and handle event dispatch distribution
3) Handlerfinder, Annotatedhandlerfinder: Used to find publishers and Subscribers
4) Eventproducer, EventHandler: Encapsulates the data structure of the Publisher and subscriber separately
"Android Advanced Light"--event bus