Android07-android Broadcast

Source: Internet
Author: User
Brief introduction of ¨ broadcasting mechanism ¨ dynamic and static registered broadcast ¨ receive system broadcast ¨ custom broadcast ¨ local broadcast n broadcast is a system-level event. n When certain events occur on the system (for example, receiving text messages, incoming calls, low power), a message is sent to the entire Android system, which is broadcast.

Every app in Android can register a broadcast of interest, so the program will only receive the broadcast content that it cares about, either from the system or from other applications.

N programmers can also customize broadcast receive broadcast n use component broadcast receiver Broadcastreceiver to receive broadcasts, broadcast receivers need to be registered to use N when receiving a broadcast, the callback function is triggered onreceive () Broadcast classification: N Standard broadcast: a broadcast that executes completely asynchronously.

After the broadcast, all broadcast receivers receive the broadcast message almost at the same time, so there is no sequencing between them. This kind of broadcast is more efficient, but it also means that it cannot be truncated.

N ordered broadcast: A broadcast that is executed synchronously.

Only one broadcast receiver will be able to receive this broadcast message at the same time, and the broadcast will continue to pass when the logic in the broadcast receiver has been executed. So at this time the broadcast receiver is in order, the priority of the broadcast receiver can receive a broadcast message, and the front of the broadcast receiver can also truncate the broadcast is being delivered, so that the subsequent broadcast receivers will not be able to receive broadcast messages.

Broadcast receivers are free to register their own broadcasts of interest, so that when a corresponding broadcast is issued, the broadcast receiver is able to receive the broadcast and process the corresponding logic internally. There are generally two ways of registering a broadcast, registering it in code and registering it in Androidmanifest.xml, where the former is also known as dynamic registration, which is also known as static registration.

Dynamic Registration monitoring Network changes

Android07-android Broadcast

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.