Android Apps four components

Source: Internet
Author: User
Tags home screen

For an Android application, it is made up of four building blocks, the four building blocks are as follows:

Activity

Intent Receiver

Service

Content Provider

However, not every Android application needs these four building blocks, which is not necessary, and at some point we only need several of these four kinds of combinations into our applications.

Once we have identified which building blocks our application needs, we need to enlist the list of these building blocks in Androidmanifest.xml. This is an XML configuration file that defines the components of our application, the capabilities and requirements of the components, and so on. This configuration file is required for every Android application. For Androidmainfest.xml schemas, refer to the documentation that came with the SDK package. Below, we make some explanations for four building blocks:

First, activity

Activity is the most basic of the Android block, where an activity is usually a separate screen. Each activity is implemented as a separate class, and inherits from the base class of activity. The activity class will display a user interface consisting of several views controls and respond to events. Most applications will contain multiple screens. For example, a short message application will have a screen to display a list of contacts, a second screen to write a short message, and a screen for browsing old short messages and for system setup. Every one of these screens is an activity. Navigating from one screen to another is easy. In some applications, a screen may even return a value to the previous screen.

When a new screen is opened, the previous screen is paused and saved in the history stack. The user can return to the previous screen in the history stack. can also be removed from the history stack when the screen is no longer in use. By default, Android will retain the run screen from the home screen to each application.

Android uses this special class of intent to move between the screen and the screen. The intent class is used to describe what an application will do. In the description structure of intent, there are two most important parts: the corresponding data of action and action. Typical action types are: MAIN (activity of the portal), VIEW, PICK, Edit and so on. The corresponding data of the action is expressed in the form of a URI. For example, to see how a person is contacted, you need to create a intent with an action type of view and a URI that represents the person.

A class that has a relationship with it is called Intentfilter. Relative to intent is a valid request to do something, a intent filter is used to describe which intent an activity (or intent Receiver) can manipulate. An activity if you want to show a person's contact, you need to declare a intentfilter, the intentfilter to know how to handle the view action and the URI that represents a person. Intentfilter need to be defined in Androidmanifest.xml.

It's easy to navigate from one screen to another by parsing various intent. When navigating forward, the activity will call the StartActivity (Intent myintent) method. The system then looks in the Intentfilter defined in all installed applications and finds the intent corresponding activity for the most matching myintent. The new activity begins to run after receiving the Myintent notification. When the StartActivity method is invoked to trigger an action that resolves myintent, this mechanism provides two key benefits:

A, activities can reuse a request from other components in the form of intent;

B, activities can be replaced at any time by a new activity with the same intentfilter.

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.