Android Service functions

Source: Internet
Author: User

This article introduces the Android Service to you. Many people may not understand the features of the Android Service. It does not matter. After reading this article, you must have learned a lot, having mastered the Android Service makes programming easier and easier.

Common examples: media player plays music from the playlist. the player has some activities that allow you to select a song and start playing it. However, you do not need to process the activity because you want to stop the activity and the song will continue playing.

Therefore, the activity of media player starts a service. After the user leaves the form, the system can still play the song. It can communicate with a running service or start a service. Communication with the service depends on the public interface of the service. For example, you can use the following APIs to pause, start, stop, or resume a playback list.

Like activities and other components, Android Service runs in the main thread of the application. Therefore, they do not block other components or user interfaces. You can enable another thread in the service for time-consuming work, such as playing music. See Processes and Threads.

Broadcast receivers
Android Service is a component that receives and processes broadcast notifications broadcast announcements. Most broadcasts are initiated by the system. Such as changing regions, insufficient battery power, image acquisition, and language conversion. A program can also initialize a broadcast, such as letting other programs know that some data they need has been downloaded. Note: Notification broadcast is an event)

The program can have any number of broadcast receivers to respond to the notifications it deems important. All receivers inherit from the BroadcastReceiver class. Broadcast receivers does not display the user interface, but they may start an activity to receive notifications accordingly.

You can also use icationicationmanager to notify users. You can enable the background light, vibration device, and play the audio in multiple ways. The most typical is to display an icon in the status bar so that you can click it to open the notification content.

Content providers
Android Service creates datasets used by other programs. Data can be stored in the SQLite database of the system or elsewhere. The content provider inherits from the ContentProvider class.

Implement a set of standard methods to allow other programs to access data. However, the program does not directly call these methods, but uses the ContentResolver object to call these methods. ContentResolve is used to manage multi-process interaction between providers and programs.

See the Content Providers documentation.
As long as there is a need to call a specific component, Android needs to ensure that the component program process is running. If the component thread is not started, it also needs to start the required process. If the required component is not initialized, Android initializes it.

When ContentResolver initiates a request, Content providers is activated. The other three components are-activities, services, and broadcast receivers-asynchronous message activation called intents. Intent is an Intent object that maintains message information. Activities and services transmit the requested data and specific URI.

For example, it may send a request called activity to present an image or ask the user to edit a text segment. For broadcast receivers, The Internt object transmits the Notification action. For example, it may notify the camera that the button is pressed.

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.