Component features in Android applications

Source: Internet
Author: User
Tags requires

Android applications typically consist of one or more components, including Activity,service, Broardcastreceiver, ContentProvider, etc.

Activity is a component in the Android application that interacts with the user, provides a visual user interface, and if the application requires multiple user interfaces, the application requires multiple activity, with multiple activity together to form the activity stack, The active activity is at the top of the stack. The activity component needs to inherit the activity base class.

The service is tied to the activity and is a separate Android component, the difference being that the service usually runs in the background, does not need to interact with the user, and does not have a graphical user interface. Service components have their own independent lifecycle, typically providing background services to other components or monitoring the running state of other components, and the service needs to inherit the service base class.

Broardcastreceiver is an important component of Android applications. From a code point of view Broardcastreceiver is very similar to the listener in event programming, except that the object it listens to is other components in the Android application. The implementation of Broardcastreceiver is simpler, just inherit the Broardcastreceiver base class and rewrite the Onreceiver method. When another component sends a broadcast message through the Sendbroardcast, Sendstickybroardcast, or Sendorderedbroardcast method, if the broardcastreceiver is also interested in the message, The Broardcastreceiver OnReceive method will be triggered.

ContentProvider

For Android applications, they have to be relatively independent, running on their own Dalvik virtual machine instances, if real-time data exchange is required between different applications. The Android system provides a standard for data interchange across applications: ContentProvider. When users implement their own contentprovider, you need to implement the following abstract methods:

Insert: Inserting data into ContentProvider

Delete: Deletes the data specified in ContentProvider

Update: Updating the data specified in ContentProvider

Query: Querying data from ContentProvider

Usually used in conjunction with ContentProvider is Contentresolver, an application uses ContentProvider to expose its own data, while another application uses Contentresolver to access the data.

Intent and Intentfilter

Strictly speaking, intent is not an Android component, but it works very well, and it is the carrier of communication between different components of Android. Intent can start another activity in the application, start a service component, and send a broadcast to trigger the Broardcastreceiver in the system. That is to say, the communication between activity,service,broardcastreceiver three components is through intent as the carrier, but the mechanism strategy of using intent for different components is slightly different.

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.