EventBus thread mode development skills and eventbus development skills
POSTING (default thread mode ):
In this mode, the event processing function runs in the thread where the event is released, that is, the event publishing and receiving and processing of the event are in the same thread.
Note: 1) Avoid time-consuming operations in the event handler function with the thread model POSTING, because it will block event transmission and may even cause ANR.
2) If you are processing UI operations when receiving events, pay attention to them here. If an event is published in a child thread, the UI cannot be updated.
Setting method:
@ Subscribe // default
Or
@ Subscribe (threadMode = ThreadMode. POSTING)
MAIN:
In this mode, no matter which thread the event is published, the event processing will be executed in the UI thread. The event processing time cannot be too long. It will be ANR for a long time.
Setting method:
@ Subscribe (threadMode = ThreadMode. MAIN)
BACKGROUND:
In this mode, no matter which thread the event is published, the event processing is carried out in the Child thread. There are two cases: if an event is released in the UI thread, the event handler function will run in the new thread, if an event is originally released in a child thread, the event handler function is executed directly in the thread where the event is published. UI update is prohibited in this event handler function.
Setting method:
@ Subscribe (threadMode = ThreadMode. BACKGROUND)
ASYNC:
In this mode, no matter which thread the event is released, the event handler function is executed in the new Child thread. Similarly, the event handler function prohibits UI update.
Setting method:
@ Subscribe (threadMode = ThreadMode. ASYNC)