EventBus thread mode development skills and eventbus development skills

Source: Internet
Author: User

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)

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.