[Android App Development] 05. Broadcasting and Services

Source: Internet
Author: User

Broadcast recipient
    • In reality: Radio to publish news, broadcast the message out, using the radio, you can listen to the radio, learned this message

    • Android: During the operation of the system, there will be many events, then some events, such as: Power changes, send and receive text messages, call, screen unlock, boot, the system will send a broadcast, as long as the application received this broadcast, the system has been aware of the corresponding event, so that the corresponding code execution. Use the broadcast receiver to listen to the broadcast

Create a broadcast recipient
    1. Defining Java class inheritance Broadcastreceiver

    2. Define the receiver node in the manifest file, define the Name property, and specify the full class name of the broadcast receiver Java class

    3. In the Intent-filter node, specify the action child node, and the action value must match the action in the broadcast to be accepted, for example, if you want to accept a call to broadcast,

Then the value of the action must be specified as

    <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    • Because the action contained in the call broadcast is "Android.intent.action.NEW_OUTGOING_CALL", so when we define the broadcast receiver,

      Action must match to receive this broadcast

    • Even if the broadcast receiver's process has been closed, when the action in the broadcast by the system matches the action of the broadcast recipient, the system initiates the process where the broadcast receiver is located and sends the broadcast to the broadcast recipient.

SMS Firewall
    • When the system sends the text message broadcast, how to put the text message content to broadcast, we only then how to take out

    • If the text message is too long, then the send will be split into multiple text messages sent, then the text message broadcast will contain more than one text message

    • After 4.0, the broadcast receiver's process will not take effect if it has never been started.

    • After 4.0, if the system automatically shuts down the process where the broadcast recipient is located, when the action on the broadcast matches the action of the broadcast recipient, the system initiates the process where the broadcast receiver is located, but if the user manually shuts down the process, the process goes into a frozen state and is never started again. Until the next time the user starts the process manually.

Broadcast classified unordered broadcast
    • All broadcast receivers that match the action on the broadcast can receive this broadcast, and are not sequential, and are considered to receive both
Orderly broadcast
    • All broadcast receivers that match the action on the broadcast can receive the broadcast, but in sequence, sorted by the priority of the broadcast recipient
Service
    • Service

    • A component running in the background for running code that runs in the background, and the service is not a front-end interface and can be viewed as an activity without an interface.

Process priority
    1. Foreground process: a process that has an activity that is interacting with the user (the Onresume method is called)

    2. Visible process: Has an activity with visible but no focus (the OnPause method is called)

    3. Service process: Has a service initiated through the StartService method

    4. Background process: a process that has an invisible activity (the OnStop method is called)

    5. Empty process: No process with any active app components

Status of Phone recorder phone

Call to detect the status of the phone, using the broadcast mechanism.

    • Idle state (phone hangs up)

        TelephonyManager.CALL_STATE_IDLE
    • Ringing status

        TelephonyManager.CALL_STATE_RINGING
    • Off-hook status (in call)

        TelephonyManager.CALL_STATE_OFFHOOK
Recorder

Recording, is to use the service.

    • The encoding and format of the audio file is not one by one corresponding

This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )
Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4912483.html

[Android App Development] 05. Broadcasting and Services

Related Article

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.