Google Android Application Structure

Source: Internet
Author: User
Tags home screen
Source: http://www.robotercoding.com/blog? P = 33

Translated by http://code.google.com/android/intro/anatomy.html

There are four components in an Android Application:
* Activity component
* Intent receiver receives processing components
* Service Components
* Content provider provides components
An android application does not need to have these four components at the same time. The application can combine these components.

Once an application determines which components are used, it must be listed in the androidmanifest. xml file. For more information, see Android manifest file documentation.

Activity
Activities are the most common component. In applications, activities are usually used to display the content of a screen (PAGE), just the content of a screen (page. Developers need to inherit from the activity base class to manage the UI display and UI feedback events. Most applications have multiple screens (pages). For example, for a text message application, the first page displays the contact list, on the second page, you need to write something to the selected contact. On other pages, the old text content or others are displayed. Every page is treated as an activity. Moving to other pages means that a new activity (Activity component) is started ). In some scenarios, an activity can return a value to the previous activity. If an image is selected for a page, the image can be returned to the caller (activit ).

When a new page is opened, the previous page will be paused and placed in a history stack. You can use the back key to browse the previous page or delete the page from the stack. Android displays the home screen (idle interface?) on the home page ?) The started application maintains a list of historical stacks.

Intent and intent Filters
Android uses an intent class to move from one page to another. An intent describes what the application is going to do. It is an action. The most important two points are: the type of the action and the parameter (data) carried by the action, the typical action type is main (the main entrance of the activity), view, pick, edit, and so on. Parameter Data is represented in Uri format. For example, to view a person's contact information, you need to create an intent. The action type is view, and the person name is parameter data (which must be formatted as URI ).

In order to indicate that an activity can process some intent, Android designs a intentfilter class. The activity determines the intent action type that it can process in intentfilter. intentfilter must be in androidmanifest. in the XML file.

The jump from one page to another is based on the intent. To forward browsing, activity callsStartactivity (myintent)In the Android system, find intent filters in all installed applications and find the activity that best matches myintent. The new activity is started and the intent is passed in. There are two key points:
* Activities can be reused.
* Activities can be replaced at any time, as long as an activity has the same intentfilter

Intent receiver er
In an application, you need to execute some actions for external events for feedback. You can use the intentreceiver class. For example, a phone call, a data tunnel is available, or a call arrives at night. Intent consumer er does not display the UI, although it can notify users of some interesting things through icationicationmanager. Intent receivers also needs to be declared in androidmanifest. xml. Of course, you can also call the context. registerreceiver () interface in the program for dynamic declaration. At the same time, intent receivers can be called when the application is not running. When an intent receivers is triggered, Android will start the application. Applications can also broadcast their intent through context. broadcastintent.

Service
A service is a code component that has no UI and has been running in the background. A good example: the player plays a song from a playlist. In a player application, there will probably be one or more activity components that allow users to select songs and play them. The song play code should not be placed in the activity component, because we want to always be able to listen to songs, even switched to other pages. Therefore, the player page should start a service component (context. startservice () to play the song. The Android system will keep the service running until it ends (refer to the "Android Application lifecycle" Article ). You can use the context. bindservice () interface to connect to the previous service (if the service is not started at this time, the connection will cause the service to start). After the connection, you can communicate with the service. For example, a player can be paused or rewound.

Content Provider
Applications can store their data in files, databases, or other devices. Content Provider is used to share the data of each application. content provider is a class that executes a set of standard methods to allow other applications to store and obtain the data processed by content provider. For more information, see accessing content providers.

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.